using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main(string[] args)
{
string sqlConnectString = "Data Source=(local);Integrated security=SSPI;Initial Catalog=AdventureWorks;";
string sqlSelect = "SELECT ContactID, FirstName, LastName FROM Person.Contact";
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectString);
DataTable dt1 = new DataTable();
da.Fill(dt1);
DataRow[] dra = new DataRow[dt1.Rows.Count];
dt1.Rows.CopyTo(dra, 0);
for (int i = 0; i < dra.Length; i++){
Console.WriteLine(
"ContactID = {0}\tFirstName = {1}\tLastName = {2}",
dra[i].Field<int>("ContactID"), dra[i].Field<string>("FirstName"),
dra[i].Field<string>("LastName"));
}
DataTable dt2 = dra.CopyToDataTable();
foreach (DataRow row in dt2.Rows)
{
Console.WriteLine(
"ContactID = {0}\tFirstName = {1}\tLastName = {2}",
row["ContactID"], row["FirstName"], row["LastName"]);
}
}
}