thukralz

DataSet ds = new DataSet();

try

{

IDbCommand fieldCheck = connection.CreateCommand();

fieldCheck.CommandText = "DatabaseFieldCheck";

fieldCheck.CommandType = CommandType.StoredProcedure;

//Add Parameters

//Table Name

IDataParameter tableN = fieldCheck.CreateParameter();

tableN.ParameterName = "@tableName";

tableN.DbType = DbType.String;

tableN.Value = tableName;

fieldCheck.Parameters.Add(tableN);

//Table Field

IDataParameter tableF = fieldCheck.CreateParameter();

tableF.ParameterName = "@fieldName";

tableF.DbType = DbType.String;

tableF.Value = tableField;

fieldCheck.Parameters.Add(tableF);

//Pass the value

IDataParameter val = fieldCheck.CreateParameter();

val.ParameterName = "@value";

val.DbType = DbType.String;

val.Value = value;

fieldCheck.Parameters.Add(val);

////Execute the Query

//IDataReader reader = fieldCheck.ExecuteReader();

IDataAdapter adapter = What should be here.....

adapter.Fill(ds);

//Close the Connection to the database

conn.DisconnectDatabaseConnection(connection);

}

My above code works fine, but If I have to fill dataset ds, how can I do with IDataAdpater or any suggestion how to do it othwerwise...

I'm using IDBCommand, I can't use SQLAdapter...



Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

VMazur

Since IDataAdapter is just an interface and not the actual class, you have to assign to this variable specific adapter, same as you do with the command. Otherwise you cannot fill the data. You could pass it as a parameter from outside to keep this part of code generic.






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

Any examples how can I do that I have tried almost everything..I guess keep it generic is giving me hard time...





Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

VMazur

You have to pass variable of SqlDataAdapter type to the code and assign it like (assuming MySqlAdapterVariable is of SqlDataAdapter type)

IDataAdapter adapter = MySqlAdapterVariable;

Then you could call Fill method






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

How can I pass the connection information, thats where it starts complaining



Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

VMazur

You need assign it to the Connection property of th IDBCommand. It would be

fieldCheck.Connection = connection;






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

Hey Sorry for bugging you, but I can't get it to work..

SqlDataAdapter adapter = new SqlDataAdapter();

IDataAdapter adp = adapter;

fieldCheck.Connection = connection;

How will adp will be used in this connection...

Really appreciate for your time...





Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

BonnieB

Try this:

adp.SelectCommand = fieldCheck;






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

IDataAdapter adp has nothing like

SelectCommand





Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

BonnieB

You're right ... sorry ... my bad.

Using the code you posted a few posts back, try instantiating the SqlDataAdapter with the SqlCommand as a parameter:

SqlDataAdapter adapter = new SqlDataAdapter(fieldCheck);

IDataAdapter adp = adapter;

fieldCheck.Connection = connection;






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

SqlDataAdapter adapter = new SqlDataAdapter(fieldCheck);

The above line will have error saying that fieldCheck is IDBCommand and cannot be changed to SqlCommand and so on





Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

BonnieB

Man, what a Catch-22!!!

Maybe you need to rethink things a bit. I've done a base DataAccess class that exposes all the public/protected properties/methods with the Interfaces, but it specifically uses SQL stuff internally. If I have a client that uses something other than SQL, then I will use a different base class substituting SQL for Oracle or whatever, but the rest of my DataAccess sub-classes (all sub-classed from the base class) will remain unchanged because they don't care whether the database is SQL or Oracle or whatever.

It's way too big a class to post here ... maybe if you need more help with this idea, I could email it to you. Email me if you need to.






Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

Harsimrat

I have been struggling with this thing for a long time now....for some stuff I have also moved using nhibernate.

I will really appreciate if you can send me ur class..

thukraldotharsimratatgmail.com





Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

BonnieB

OK, I sent you something ... I hope I got your email right. Let me know if you don't get it (my email is in my profile ... click on my name).




Re: .NET Framework Data Access and Storage How to use IDataAdapter ??

BonnieB

email me ... my email to you got bounced back.