/// 获取存储过程的参数列表
/// </summary>
/// <param name="proc_Name">存储过程名称</param>
/// <returns>DataTable</returns>
private static DataTable GetParameters(string proc_Name)
{
SqlCommand comm = new SqlCommand("dbo.sp_sproc_columns_90", new SqlConnection(SqlHelper.ConnectionStringMBCheckoutPayPal));
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@procedure_name", (object)proc_Name);
SqlDataAdapter sda = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
/// 为 SqlCommand 添加参数及赋值
/// </summary>
/// <param name="comm">SqlCommand</param>
/// <param name="paraValues">参数数组(必须遵循存储过程参数列表的顺序)</param>
private static void AddInParaValues(SqlCommand comm, params object[] paraValues)
{
comm.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int));
comm.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
if (paraValues != null)
{
DataTable dt = GetParameters(comm.CommandText);
int i = 0;
foreach (DataRow row in dt.Rows)
{
string key = row[3].ToString();
if (key != "@RETURN_VALUE")
{
int value = int.Parse(row[4].ToString());
if (value == 1)
{
comm.Parameters.AddWithValue(key, paraValues[i]);
}
else if (value == 2)//value为2则是输出参数
{
comm.Parameters.AddWithValue(key, paraValues[i]).Direction = ParameterDirection.Output;
//comm.Parameters[key].Direction = ParameterDirection.Output;
}
i++;
}
}
}
}