存储过程的输出参数,返回值与结果集

网络整理 - 08-23


protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=1;");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText="Employee";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter para = new SqlParameter("@Rowcount", SqlDbType.Int, 4);
para.Direction = ParameterDirection.Output;
cmd.Parameters.Add(para);
cmd.Parameters.Add("@return_value", SqlDbType.Int, 4);
cmd.Parameters["@return_value"].Direction = ParameterDirection.ReturnValue;
con.Open();
cmd.ExecuteNonQuery();
Response.Write(cmd.Parameters["@Rowcount"].Value.ToString()+"<br/>");
Response.Write(cmd.Parameters["@return_value"].Value.ToString());
}