using System; using System.Data; using System.Data.Common; using System.Data.Odbc; namespace STMes.DataProvider { /// /// Implements access to the Data Provider for ODBC. /// /// /// See the method to find an example. /// /// AddDataManager Method public class OdbcDataProvider: IDataProvider { /// /// Creates the database connection object. /// /// /// See the method to find an example. /// /// AddDataManager Method /// The database connection object. IDbConnection IDataProvider.CreateConnectionObject() { return new OdbcConnection(); } IDbConnection IDataProvider.CreateConnectionObject(string connectionString ) { OdbcConnection conn = new OdbcConnection(connectionString); return conn; } /// /// Creates the data adapter object. /// /// /// See the method to find an example. /// /// AddDataManager Method /// A data adapter object. DbDataAdapter IDataProvider.CreateDataAdapterObject() { return new OdbcDataAdapter(); } /// /// Populates the specified IDbCommand object's Parameters collection with /// parameter information for the stored procedure specified in the IDbCommand. /// /// /// See the method to find an example. /// /// AddDataManager Method /// The IDbCommand referencing the stored procedure for which the parameter information is to be derived. The derived parameters will be populated into the Parameters of this command. void IDataProvider.DeriveParameters(IDbCommand command) { OdbcCommandBuilder.DeriveParameters((OdbcCommand)command); } /// /// Returns connection type. /// /// /// See the method to find an example. /// /// AddDataManager Method /// An instance of the class. public Type ConnectionType { get { return typeof(OdbcConnection); } } /// /// Returns the data provider name. /// /// /// See the method to find an example. /// /// AddDataProvider Method /// Data provider name. public string Name { get { return "Odbc"; } } /// /// /// /// public IDbDataParameter CreateDataParameter() { // TODO: 添加 OdbcDataProvider.CreateDataParameter 实现 return new OdbcParameter(); } /// /// /// /// /// public Object CreateCommandBuilder(DbDataAdapter da) { return new OdbcCommandBuilder(da as OdbcDataAdapter) as object; } /// /// Test Connection Info(ODBC) /// /// Test Connection Object /// Test Result public bool Ping(ref IDbConnection db) { // TODO: 添加 OdbcDataProvider.Ping 实现 return true; } public int GetSID(ref IDbConnection db) { return -1; } } }