ASP.NET中调用事务处理的方法
/// <summary> /// 事务处理 /// </summary> /// <param name="strSql"></param> /// <returns></returns> public bool InportData(string strSql) { SqlConnection sqlConnection = new SqlConnection(DbHelperSQL.connectionString); sqlConnection.Open(); SqlTransaction myTrans = sqlConnection.BeginTransaction(); SqlCommand sqlInsertCommand = new SqlCommand(); sqlInsertCommand.Connection = sqlConnection; sqlInsertCommand.Transaction = myTrans; try { sqlInsertCommand.CommandText = strSql.ToString(); sqlInsertCommand.ExecuteNonQuery(); myTrans.Commit(); return true; } catch (Exception ex) { myTrans.Rollback(); return false; } finally { sqlConnection.Close(); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。