Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Server=zhuobin;uid=sa;pwd=zhuobin;database=Northwind");
try
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_selectAll";
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine("{0}{1}{2}", rdr[0].ToString().PadRight(5), rdr[1].ToString(), rdr[2].ToString());
} rdr.Close();
}
catch (SqlException ex)
{
Console.WriteLine("The Error:{0}", ex.Message);
}
finally
{
conn.Close();
} Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Server=zhuobin;uid=sa;pwd=zhuobin;database=Northwind");
try
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_selectAll";
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine("{0}{1}{2}", rdr[0].ToString().PadRight(5), rdr[1].ToString(), rdr[2].ToString());
} rdr.Close();
}
catch (SqlException ex)
{
Console.WriteLine("The Error:{0}", ex.Message);
}
finally
{
conn.Close();
} Console.ReadKey();
}
}
}