- static void Main(string[] args)
- {
-
- SqlConnection sqlConn = new SqlConnection(
- ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
- SqlTransaction sqlTrans = null;
- try
- {
- sqlConn.Open();
- sqlTrans = sqlConn.BeginTransaction();
- SqlCommand sqlComm = new SqlCommand("", sqlConn, sqlTrans);
- sqlComm.CommandTimeout = 120;
- sqlComm.CommandType = System.Data.CommandType.Text;
-
- string insertSql = "insert into dbo.TransTestTable values (66,'66');";
- string updateSql = "update dbo.TransTestTable set [Name] = '77' where [Id] = 66;";
-
- sqlComm.CommandText = insertSql;
- sqlComm.ExecuteNonQuery();
-
- sqlComm.CommandText = updateSql;
- sqlComm.ExecuteNonQuery();
-
-
- sqlTrans.Commit();
- }
- catch (Exception ex)
- {
- sqlTrans.Rollback();
- Console.WriteLine(ex.Message);
- }
- finally
- {
- if (sqlConn.State != System.Data.ConnectionState.Closed)
- sqlConn.Close();
- }
-
- Console.ReadLine();
- }
posted @
2015-10-16 16:15
斌言
阅读(
376)
评论()
编辑
收藏
举报