ASP.NET中调用事务处理的方法
时间:2015-01-14 21:07:56
收藏:0
阅读:323
/// <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();
}
}
原文:http://www.cnblogs.com/luoyangcn/p/4224790.html
评论(0)