Code
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. Data;
Using System. Data. sqlclient;
Namespace Leleapplication1
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Sqlconnection Conn = New Sqlconnection ( " Server = zhuobin; uid = sa; Pwd = zhuobin; database = northwind " );
String SQL = @" Select companyName, contactname from customers where contactname like'm %' " ;
Try
{
Conn. open ();
Sqlcommand cmd = New Sqlcommand (SQL, Conn );
Sqldatareader Reader = Cmd. executereader ();
Console. writeline ( " \ T {0} {1} " , " CompanyName " . Padright ( 25 ), " Contactname " . Padright ( 20 ));
Console. writeline ( " \ T {0} {1} " , " ============== " . Padright ( 25 ), " ============== " . Padright ( 20 ));
While (Reader. Read ())
{
Console. writeline ( " \ T {0} | {1} " , Reader [ 0 ]. Tostring (). padright ( 25 ), Reader [ 1 ]. Tostring (). padright ( 20 ));
}
}
Catch (Sqlexception ex)
{
Console. writeline ( " Error: {0} " , Ex. Message );
}
Finally
{
}console. Readline ();
}< BR >}< br>