using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["textconnstring"].ToString()))
{
if (conn.State == ConnectionState.Closed)
conn.Open();
SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sqlStr1;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();
cmd.CommandText = sqlStr2;
cmd.Transaction = trans;
cmd.ExecuteNonQuery();
using (SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["textconnstring"].ToString()))
{
SqlCommand cmd1 = new SqlCommand(sqlStr, conn1);
SqlDataAdapter sda = new SqlDataAdapter(cmd1);
DataSet ds =new DataSet();
sda.Fill(ds);
}
trans.Commit();
}catch(SqlException ex)
{
trans.Rollback();
Console.WriteLine(ex.Message);
}
}
红颜莎娜
翻阅古今