public static string Save_list( string CreateDate)
{
string sql = "pc_insert_list";
string returnValue = string.Empty;
try
{
SqlParameter[] sp = {
new SqlParameter("@CreateDate",CreateDate) ,
new SqlParameter("@ReturnId",SqlDbType.VarChar,50)
};
returnValue = DBHelper.NonQueryTwo(1,CommandType.StoredProcedure, sql, sysName, sp);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return returnValue;
}
/// <summary>
/// 执行数据的增、删、改方法
/// </summary>
/// <param name="type">要执行的数据库命令类型</param>
/// <param name="CommandText">要执行的SQL语句或存储过程</param>
/// <param name="pars">所需的参数列表</param>
/// <returns>受影响的行数</returns>
public static string NonQueryTwo( int n,CommandType type, string CommandText, string sysName, params SqlParameter[] pars)
{
string str = string.Empty;
using (SqlConnection Connection = new SqlConnection(strConn(sysName)))
{
Connection.Open();
//实例化数据库命令对象
SqlCommand cmd = new SqlCommand(CommandText, Connection);
try
{
//设置命令执行类型
cmd.CommandType = type;
//设置SQL语句或存储过程参数
pars[n].Direction = ParameterDirection.Output;//第几位要设返回值
cmd.Parameters.AddRange(pars);
//调用方法得到SqlDataReader对象
int ii = cmd.ExecuteNonQuery();//不管受不受影响,都会有返回值
str = cmd.Parameters["@ReturnId"].Value.ToString();
return str;
}
catch (Exception err)
{
cmd.Dispose();
Connection.Close();
Connection.Dispose();
throw new Exception(err.Message);
}
finally
{
Connection.Close();
Connection.Dispose();
}
}
}
C#的赋值和接收值代码如上,sql语句也是赋值为 output 就可以