using System;
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 ";
SqlConnection connection = new SqlConnection(sqlConnectString);
SqlCommand command = new SqlCommand(sqlSelect, connection);
connection.Open( );
using (SqlDataReader dr = command.ExecuteReader( ))
{
while (dr.Read( ))
{
Console.WriteLine(dr["ContactID"]);
Console.WriteLine(dr["LastName"]);
Console.WriteLine(dr["FirstName"]);
}
}
connection.Close( );
}
}
|