sqlserver获取存储过程返回值
1.OUPUT参数返回值 [sql]? view plain copy
存储过程中获得方法:
DECLARE ? @o_buyerid int @o_id bigint EXEC ? [ nb_order_insert ] ,@o_id? output 2.RETURN过程返回值 存储过程中的获取方法 3.SELECT 数据集返回值 nb_order_selectint 存储过程中的获取方法 (1)、使用临时表的方法 CREATE TABLE dbo . Temp ( ![]() (2)、速度不怎么样.(不推荐) from openrowset (’provider_name ' ' Trusted_Connection yes’,0)">exec?nb_order_select’) 1.获取Return返回值 //存储过程 //Create PROCEDURE MYSQL //???? @a int, //???? @b int //AS //???? return @a + @b //GO SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()); conn.Open(); SqlCommand MyCommand = new SqlCommand("MYSQL",conn); MyCommand.CommandType = CommandType.StoredProcedure; MyCommand.Parameters.Add(new SqlParameter("@a",SqlDbType.Int)); MyCommand.Parameters["@a"].Value = 10; MyCommand.Parameters.Add(new SqlParameter("@b",SqlDbType.Int)); MyCommand.Parameters["@b"].Value = 20; MyCommand.Parameters.Add(new SqlParameter("@return",SqlDbType.Int)); MyCommand.Parameters["@return"].Direction = ParameterDirection.ReturnValue; MyCommand.ExecuteNonQuery(); Response.Write(MyCommand.Parameters["@return"].Value.ToString()); //???? @c int output //AS //???? Set @c = @a + @b //GO SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()); conn.Open(); SqlCommand MyCommand = new SqlCommand("MYSQL",SqlDbType.Int)); MyCommand.Parameters["@a"].Value = 20; MyCommand.Parameters.Add(new SqlParameter("@b",SqlDbType.Int)); MyCommand.Parameters["@b"].Value = 20; MyCommand.Parameters.Add(new SqlParameter("@c",SqlDbType.Int)); MyCommand.Parameters["@c"].Direction = ParameterDirection.Output; MyCommand.ExecuteNonQuery(); Response.Write(MyCommand.Parameters["@c"].Value.ToString()); C#接收存储过程返回值: ???? public static int User_Add(User us) C#接收存储过程输出参数: ??? public static decimal Cart_UserAmount(int UID) ??? { ??????? decimal iRet; ??????? SqlConnection conn = new SqlConnection(Conn_Str); ??????? SqlCommand cmd = new SqlCommand("Cart_UserAmount",conn); ??????? cmd.CommandType = CommandType.StoredProcedure; ??????? cmd.Parameters.AddWithValue("@UID",UID); cmd.Parameters.Add("@Amount",SqlDbType.Decimal).Direction=ParameterDirection.Output; ??????? try ??????? { ??????????? conn.Open(); ??????????? cmd.ExecuteNonQuery(); ????????????iRet = (decimal)cmd.Parameters["@Amount"].Value; ??????? } ??????? catch (SqlException ex) ??????? { ??????????? throw ex; ??????? } ??????? finally ??????? { ??????????? conn.Close(); ??????? } ??????? return iRet; ??? } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |