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);
Console.WriteLine("FirstName = {0}", dt.Rows[2][1]);
Console.WriteLine("FirstName = {0}", dt.Rows[2]["FirstName"]);
Console.WriteLine("FirstName = {0}",dt.Rows[2]["FirstName", DataRowVersion.Default]);
Console.WriteLine("FirstName = {0}", dt.Rows[2][dt.Columns[1]]);
Console.WriteLine("FirstName = {0}",dt.Rows[2][dt.Columns["FirstName"]]);
Console.WriteLine("FirstName = {0}",dt.Rows[2].Field<string>(1));
Console.WriteLine("FirstName = {0}",dt.Rows[2].Field<string>("FirstName"));
Console.WriteLine("FirstName = {0}",dt.Rows[2].Field<string>("FirstName", DataRowVersion.Default));
Console.WriteLine("FirstName = {0}",dt.Rows[2].Field<string>(dt.Columns[1]));
Console.WriteLine("FirstName = {0}",dt.Rows[2].Field<string>(dt.Columns["FirstName"]));
}
}
|