以下是C#代码:
////// 执行存储过程,返回" 返回值"/// /// 存储过程名/// 存储过程参数///执行存储过程的返回值 public static int RunProcedureWithReturn(string storedProcName, IDataParameter[] parameters){using (SqlConnection connection = new SqlConnection(connectionString)){int result;connection.Open();SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);command.ExecuteNonQuery();result = (int)command.Parameters["ReturnValue"].Value;//Connection.Close();return result;}}////// 创建 SqlCommand 对象实例(用来返回一个整数值) /// /// 存储过程名/// 存储过程参数///SqlCommand 对象实例 private static SqlCommand BuildIntCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters){SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);command.Parameters.Add(new SqlParameter("ReturnValue",SqlDbType.Int, 4, ParameterDirection.ReturnValue,false, 0, 0, string.Empty, DataRowVersion.Default, null));return command;}
详细请下载源代码
使用VS2015+SQL 2008
参考:谜语:
更多文章: