private void DemoTranscation() { DataTable dt = new DataTable(); SqlConnection conn = new SqlConnection(@"Data Source=XK\SQLEXPRESS;Initial Catalog=newssystem;Integrated Security=SSPI"); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { SqlCommand comm = new SqlCommand("select * from news", conn); comm.Transaction = tran; using (SqlDataReader sdr = comm.ExecuteReader()) { dt.Load(sdr); tran.Commit(); } } catch { tran.Rollback(); throw new Exception("出错了!!!"); } finally { conn.Close(); } }