存储过程
alter procedure NorthwindSearch
(
@productID int
)
as
return 1
go
获取存储过程返回值代码
protected void btnBack_Click(object sender, EventArgs e)
{
//调用存储过程
stringconStr=ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString();
SqlConnection conn = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "NorthwindSearch";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection=conn;
conn.Open();
SqlParameter sp = new SqlParameter("@productID", SqlDbType.Int);
sp.Value = int.Parse(txtProduct.Text.Trim());
cmd.Parameters.Add(sp);
//定义输出参数
SqlParameter returnValue = new SqlParameter("@returnValue", SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(returnValue);
cmd.ExecuteNonQuery();
txtSupplierID.Text = returnValue.Value.ToString();
conn.Close();
}
注意,(return)这种方式 只能返加数值类型
参考资料 : 如何获取存储过程返回值 http://www.studyofnet.com/news/427.html