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 dt = new DataTable();
da.Fill(dt);
DataRow[] dra = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(dra, 0);
Console.WriteLine("FirstName = {0}",dra[2].Field<string>("FirstName"));
Console.WriteLine("FirstName = {0}",dra[2].Field<string>("FirstName", DataRowVersion.Default));
}
}
|