Click to See Complete Forum and Search --> : How to do this in a better way%


Spotnick
October 8th, 2002, 01:30 PM
It might not be the best way to navigate through a recordset, but is there an actual way to do the following code better?


private void button1_Click(object sender, System.EventArgs e)
{
ADODB.Connection objConnection = new ADODB.ConnectionClass();
ADODB.Recordset rsData = new ADODB.RecordsetClass();

objConnection.Open("Provider=SQLOLEDB;User ID=daing;Password=daing;Initial Catalog=D42DAIng;Data Source=HERCULES", "daing", "daing", 0);

rsData.Open("select * from t016_achat", objConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1);

while (!rsData.EOF)
{
MessageBox.Show(rsData.Fields["CleUniqueA"].Value.ToString());
rsData.MoveNext();
}

}


Funny, I found no information at all on the RecordsetClass, so I guess this is not the way to proceed!!

WillemM
October 31st, 2002, 05:47 AM
Try adding a Dataset to your project and fill it like this.

SqlDataAdapter1.Fill(dataSet1);

And after that you can access the data from there with this:

string name;

name = (string) dataSet1.Tables["blahblah"]["name"];

MessageBox.Show(this,name);

Arild Fines
October 31st, 2002, 09:40 AM
Any particular reason you're not using ADO.NET?

WillemM
October 31st, 2002, 12:24 PM
No particular reason :)
But I agree it's smarter to use ADO.NET