DataSet question

K

Keith Smith

I use this method to read from my Access database...

DataSet ReadDatabase(string strSQL)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\database.MDB";
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbDataAdapter myCmd = new OleDbDataAdapter( strSQL, myConn );
myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet);
return dtSet;
myConn.Dispose();
}


So then, for example, if I want to call the above method I do it this way...

DataSet x;
x = ReadDatabase("SELECT * FROM users WHERE (username='tom' AND
password='password');");

My way of doing this seems very logical to me...but I am still learning. Is
there anything wrong (or inefficient) with me doing this? The above code
seems to work fine.
 
D

DKode

if that works for you it seems to be alright,

all i would suggest is if you have other methods that need to connect
to your database, seperate out the connection code so that you are not
re-writing connection code in each of your methods, then place all of
this into data handling class.

The microsoft Data Access Application Block works very well for
connecting to database and I use it often as a data abstraction layer.

hope that helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top