For each row in DataSet, reference the column data by column name
using System;
using System.Data;
using System.Data.SqlClient;
class Class1{
static void Main(string[] args){
SqlConnection thisConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT ID, FirstName FROM Employee", thisConnection);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "Employee");
foreach (DataRow theRow in thisDataSet.Tables["Employee"].Rows)
{
Console.WriteLine(theRow["ID"] + "\t" + theRow["FirstName"]);
}
}
}
Related examples in the same category