Click here to Skip to main content
15,314,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I add constructor to take SQL statement and connection object or How can I add connection object for this class?

C#
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
    }
Posted
Updated 30-Dec-10 15:34pm
v2
Comments
Venkatesh Mookkan 30-Dec-10 21:34pm
   
Always use code block option to add codes

So simple add the below code into your class,

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

        }


Mark it as answer if it helpful
   
v3
Comments
Mostafa Elsadany 30-Dec-10 21:43pm
   
so how i can add connection to class
as

oledbDataAdapter x=new oledbDataAdapter("select * from emp",connection);
can you tell me how
i assign to my class this connection and select statement
tnx for any help
Venkatesh Mookkan 30-Dec-10 21:58pm
   
You know what you are confusing us.
Mostafa Elsadany 30-Dec-10 21:58pm
   
DbConnection connection how i can assign or pass this parameter
to any method
if you want to construct your own classes then try this:

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);
}
}
   
v3
Comments
Mostafa Elsadany 31-Dec-10 19:34pm
   
thank you so much
really i look for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900