using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
class Program
{
static void Main(string[] args)
{
string sqlConnectString = "Data Source=(local);Integrated security=SSPI;Initial Catalog=AdventureWorks;";
string sqlSelect = "SELECT TOP 5 ContactID, FirstName, MiddleName, LastName FROM Person.Contact";
SqlConnection connection = new SqlConnection(sqlConnectString);
SqlCommand command = new SqlCommand(sqlSelect, connection);
connection.Open();
using (SqlDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
int contactID = Convert.ToInt32(dr[0]);
String firstName = Convert.ToString(dr[1]);
String middleName = Convert.ToString(dr[2]);
String lastName = Convert.ToString(dr[3]);
Console.WriteLine("{0}\t{1}, {2} {3}",contactID, lastName, firstName, middleName);
}
}
}
}