![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
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.CommandText = "sp_orderbyid";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter employeeid = new SqlParameter();
employeeid.ParameterName = "@employeeid";
employeeid.SqlDbType=SqlDbType.Int;
employeeid.Direction = ParameterDirection.Input;
employeeid.Value = 2;
cmd.Parameters.Add(employeeid);
//
SqlParameter outParm = new SqlParameter("@ordercount",SqlDbType.Int);
outParm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(outParm);
//
SqlParameter retval = new SqlParameter();
retval.ParameterName = "return_value";
retval.SqlDbType = SqlDbType.Int;
retval.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(retval);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine("{0}{1}",rdr[0].ToString().PadRight(5),rdr[1].ToString());
}
rdr.Close();
//Display the output parameter
Console.WriteLine("The output Parameter value is {0}", cmd.Parameters["@ordercount"].Value);
Console.WriteLine("The return value is {0}",cmd.Parameters["return_value"].Value);
}
catch (SqlException ex)
{
Console.WriteLine("Error:{0}", ex.Message);
}
finally
{
conn.Close();
}
Console.ReadLine();
}
}
}