本文介绍了继承System.Data.Common.DbDataAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加构造函数以使用SQL语句和连接对象,或者如何为此类添加连接对象?

How can I add constructor to take SQL statement and connection object or How can I add connection object for this class?

public class Class3 : System.Data.Common.DbDataAdapter, IDataAdapter
    {
        #region IDataAdapter Members
        int IDataAdapter.Fill(DataSet dataSet)
        {
            return this.Fill(dataSet);
        }
        DataTable[] IDataAdapter.FillSchema(DataSet dataSet, SchemaType schemaType)
        {
            return this.FillSchema(dataSet, schemaType);
        }
        IDataParameter[] IDataAdapter.GetFillParameters()
        {
            return this.GetFillParameters();
        }
        MissingMappingAction IDataAdapter.MissingMappingAction
        {
            get
            {
                return MissingMappingAction;
            }
            set
            {
                MissingMappingAction = value;
            }
        }
        MissingSchemaAction IDataAdapter.MissingSchemaAction
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        ITableMappingCollection IDataAdapter.TableMappings
        {
            get { return this.TableMappings; }
        }
        int IDataAdapter.Update(DataSet dataSet)
        {
            return this.Update(dataSet);
        }
        public int FillFromReader(DataTable dataTable, IDataReader dataReader)
        {
            return this.Fill(dataTable, dataReader);
        }
        #endregion
    }

推荐答案

public Class3(DbConnection connection, string sql)
            : base()
        {
            //Do your stuff

        }



如果有帮助,请将其标记为答案



Mark it as answer if it helpful


public class MyConnection : DbConnection
{
public MyConnection(string connectionString):base()
{
// do any thing.
this.ConnectionString = connectionString;
}
}
public class MyCommand : DbCommand
{
public MyCommand(string sql,MyConnection connection):base()
{
// do any thing.
this.CommandText = sql;
this.Connection = connection;
}
}
public MyAdapter : DbAdapter
{
public MyAdapter(string sql, MyConnection connection):base()
{
this.SelectCommand = new MyCommand(sql, connection);
}
}


这篇关于继承System.Data.Common.DbDataAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 14:32