Asp.Net中调用存储过程并返回输出参数

 1  /// <summary>
 2         /// 调用存储过程返回参数
 3         /// </summary>
 4         /// <param name="orderId"></param>
 5         /// <param name="cancelOrderReson"></param>
 6         /// <returns></returns>
 7         private string[] CancelOrderProcedure(int orderId, string cancelOrderReson)
 8         {
 9             string constr = DbHelperSQL.connectionString;
10             SqlConnection conn = new SqlConnection(constr);
11             conn.Open();
12             SqlCommand cmd = new SqlCommand();
13             cmd.Connection = conn;
14             cmd.CommandText = "Remy_Customer_CancelRedeemOrder";
15             cmd.CommandType = CommandType.StoredProcedure;
16             //参数一
17             SqlParameter parameter_OrderId = new SqlParameter("@RedeemOrderId", SqlDbType.Int);
18             parameter_OrderId.Direction = ParameterDirection.Input;
19             parameter_OrderId.Value = orderId;
20             //参数二
21             SqlParameter parameter_OrderRemind = new SqlParameter("@RedeemOrderRemind", SqlDbType.NVarChar, 50);
22             parameter_OrderRemind.Direction = ParameterDirection.Input;
23             parameter_OrderRemind.Value = cancelOrderReson;
24 
25             SqlParameter parameter_ReturnCode = new SqlParameter("@ReturnCode", SqlDbType.NVarChar, 50);
26             parameter_ReturnCode.Direction = ParameterDirection.Output;
27             parameter_ReturnCode.Value = "";
28             SqlParameter parameter_ReturnReason = new SqlParameter("@ReturnReason", SqlDbType.NVarChar, 200);
29             parameter_ReturnReason.Direction = ParameterDirection.Output;
30             parameter_ReturnReason.Value = "";
31 
32             cmd.Parameters.Add(parameter_OrderId);
33             cmd.Parameters.Add(parameter_OrderRemind);
34 
35             cmd.Parameters.Add(parameter_ReturnCode);
36             cmd.Parameters.Add(parameter_ReturnReason);
37             try
38             {
39                 cmd.ExecuteNonQuery();
40             }
41             finally
42             {
43                 conn.Close();
44             }
45             string[] cancelResult = new String[2] { parameter_ReturnCode.Value.ToString(), parameter_ReturnReason.Value.ToString() };
46             return cancelResult;
47         }

 

posted @ 2015-01-14 15:01  落日云烟  阅读(179)  评论(0编辑  收藏  举报