Provides a Oledb implementation for DataAccessCore. This block can be used to connect to any Oledb exposed database.
Namespace:
CA.Blocks.DataAccessAssembly: CA.Blocks.DataAccess (in CA.Blocks.DataAccess.dll) Version: 1.0.0.0
Remarks
source code:
//Source code from the Code Associate C# code library, Full documentation and latest updates can be found //@ http://www.codeassociate.com/caapi/ //=============================================================================== // Code Associate Data Access Block for .NET // DataAccessCore.cs // //=============================================================================== // Copyright (C) 2002-2010 Ravin Enterprises Ltd. // All rights reserved. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR // FITNESS FOR A PARTICULAR PURPOSE. //=============================================================================== using System; using System.Data; using System.Data.Common; using System.Data.OleDb; namespace CA.Blocks.DataAccess { public class OledbDataAccess : DataAccessCore { public OledbDataAccess(string connectionString) : base(connectionString) { } protected override bool PrepCommand(IDbCommand cmd) { OleDbConnection oleDbConnection = new OleDbConnection(ConnectionString); oleDbConnection.Open(); cmd.Connection = oleDbConnection; return true; } protected override DbDataAdapter GetDataAdapter(IDbCommand cmd) { return (new OleDbDataAdapter((OleDbCommand)cmd)); } public static OleDbCommand CreateBlankStoredProcedureCommand(string strStoredProcedureName, bool bolIncludeReturnValue) { OleDbCommand olecmd = new OleDbCommand(); olecmd.CommandText = strStoredProcedureName; olecmd.CommandType = CommandType.StoredProcedure; if (bolIncludeReturnValue) { OleDbParameter OleDbParameter; OleDbParameter = olecmd.CreateParameter(); OleDbParameter.ParameterName = "Return"; OleDbParameter.DbType = DbType.Int32; OleDbParameter.Direction = ParameterDirection.ReturnValue; olecmd.Parameters.Add(OleDbParameter); } return (olecmd); } public static OleDbCommand CreateBlankStoredProcedureCommand(string strStoredProcedureName) { return (CreateBlankStoredProcedureCommand(strStoredProcedureName, false)); } public static OleDbCommand CreateDynamicSQLCommand(string strSQL) { OleDbCommand olecmd = new OleDbCommand(); olecmd.CommandText = strSQL; olecmd.CommandType = CommandType.Text; return (olecmd); } - #region ParemeterHelpers public OleDbParameter AddInputParamCommand(OleDbCommand cmd, string strParameterName, object objParameterValue, DbType odbType, int maxParamSize) { OleDbParameter oleparam = new OleDbParameter(strParameterName, odbType); oleparam.Direction = ParameterDirection.Input; if (maxParamSize > 0) oleparam.Size = maxParamSize; if (objParameterValue == null || objParameterValue == DBNull.Value) { oleparam.Value = DBNull.Value; //Added the following as sometimes the type is changed to int32 oleparam.DbType = odbType; } else oleparam.Value = objParameterValue; cmd.Parameters.Add(oleparam); return (oleparam); } public static OleDbParameter AddOutputParamCommand(OleDbCommand cmd, string strParameterName, DbType odbType, Int32 maxParamSize) { OleDbParameter oleparam = new OleDbParameter(strParameterName, odbType); oleparam.Direction = ParameterDirection.Output; if (maxParamSize > 0) oleparam.Size = maxParamSize; cmd.Parameters.Add(oleparam); return (oleparam); } #endregion } }