ASP.NET获取存储过程返回值

来源:互联网 发布:淘宝库存同步软件 编辑:程序博客网 时间:2024/06/01 08:57

存储过程

 

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

 

0 0
原创粉丝点击