也求一事务回滚程序,请教高手!
public int proc_returnid(string sqlstr)
{
using (SqlConnection conn = new SqlConnection(connection()))
{
try
{
SqlCommand cmd = new SqlCommand( "addsimpstor ", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter para;
para = cmd.Parameters.Add( "@csql ", SqlDbType.VarChar, 7500);
cmd.Parameters[ "@csql "].Value = sqlstr;
para = cmd.Parameters.Add( "@returnid ", SqlDbType.Int);
para.Direction = ParameterDirection.Output;
para = cmd.Parameters.Add( "@retime ", SqlDbType.VarChar, 500);
para.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
return Convert.ToInt32(cmd.Parameters[ "@returnid "].Value);
}
catch (Exception ex)
{
errmessage.logerr(sqlstr);
return 0;
}
}
}
以上执行的是一个插入程序
注释:
SqlDataReader read;
int i;
程序开始
while read.rea