SQL Results to Variables

dcolanduno

New member
Joined
Nov 21, 2008
Messages
2
Location
Atlanta, GA
Hello,

I am trying to figure out how to best program a part of a new .NET site I am working on. Sadly, due to a medical issue, I havent been able to get back into programming for the past three years, and it seems that some of my .NET mojo has been way too lazy. <sigh>

So, I have a SQL connection in my ASP.NET application working, and can use some of the built in tools to see the records in the database. But, what I really want is to put the results of my query into some form of recordset where I can assign results into different variables so I can use them within the application.

Kind of like retrieving a different variable for each requested field inside the SQL Server record returned.

What is the best way to accomplish this? I seem to be barking up the wrong tree in the efforts I have made so far.

Thank you,

Derek C.
 
You probably want to look into the DataSet object, it is the .NET version of a RecordSet.

Once you populate the DataSet, you access it like this:

Code:
foreach(DataRow dr in dsObject.Tables["tableName"].Rows)
{
    int yourVariable = int.Parse(dr["fieldName"].ToString());
}
 
You can also populate a sqldatareader. I have had much success with it.

It seems to take a long time to fill a dataset/datatable. Especially if you have no intentions of editing the returned dataset.
 
Back
Top