class Program
{
static void Main(string[] args)
{
string sql = "usp_update";//事务
SqlParameter[] sqlParameters = new SqlParameter[]//参数
{
new SqlParameter("@inputlow",5),
new SqlParameter("@inputhigh",5),
new SqlParameter("@intputid",5)
};
Console.WriteLine( procedure(sql,sqlParameters));
}
static int procedure(string procedure,SqlParameter[] parameter)
{
string connectStr = "server = 192.168.0.103;database = HealthDB;uid = sa;pwd = 666666";
SqlConnection sqlConnection = new SqlConnection(connectStr);
SqlCommand sqlCommand = new SqlCommand();
try
{
sqlConnection.Open();
//------------------------------------------------------------------------------------------------------------
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.StoredProcedure;//当前操作是执行存储过程
sqlCommand.Parameters.AddRange(parameter);
sqlCommand.CommandText = procedure;//设置存储过程参数
return sqlCommand.ExecuteNonQuery();
//------------------------------------------------------------------------------------------------------------
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
ADO.net执行带参数的事务
最新推荐文章于 2022-01-08 10:52:30 发布