/// <Summary>
/// Execute multiple SQL statements to implement database transactions.
/// </Summary> sql2000 database
/// <Param name = "SQLStringList"> Multiple SQL statements </param>
Public static void ExecuteSqlTran (List <string> SQLStringList)
{
Using (SqlConnection conn = new SqlConnection (SqlHelper. ConString ))
{
Conn. Open ();
SqlCommand cmd = new SqlCommand ();
Cmd. Connection = conn;
SqlTransaction tx = conn. BeginTransaction ();
Cmd. Transaction = tx;
Try
{
For (int n = 0; n <SQLStringList. Count; n ++)
{
String strsql = SQLStringList [n]. ToString ();
If (strsql. Trim (). Length> 1)
{
Cmd. CommandText = strsql;
Cmd. ExecuteNonQuery ();
}
}
Tx. Commit ();
}
Catch (System. Data. SqlClient. SqlException E)
{
Tx. Rollback ();
Throw new Exception (E. Message );
}
}
}
Foreground call:
Try
{
// 1. Check the member balance
Decimal usermoney = SqlDal. EntityUserinfo. GetModel (int. Parse (cookieUserID). Money;
// 2. Modify the balance
Decimal Zmoney = usermoney + moAD. Commission;
// Write an SQL statement
List <string> SQLStringList = new List <string> ();
String clickSql = "insert into [user] (name, age) values ('" + nickname + "', '" + 4 years old + "')";
String userSql = "update [class] set [name] = '" + kindergarten + "'where id =" + 2 + "";
SQLStringList. Add (clickSql );
SQLStringList. Add (userSql );
SqlDal. SqlHelper. ExecuteSqlTran (SQLStringList );
// Database operation successful
// Prompt
CommonClass. Xmls xmls1 = new CommonClass. Xmls ();
String path1 = CommonClass. Unit. GetMapPath (@ "/Admin/Configs/SysSettingInfo. config ");
String ClickTishi = xmls1.GetXmlNode (path1, "SysSettingInfo/ClickTishi ");
// Replace the character
ClickTishi = ClickTishi. Replace ("[$]", moAD. Commission. ToString ("0.00 "));
Context. Response. Write (ClickTishi); // output
}
Catch (Exception ex)
{
// Response. Write (ex. Message );
Context. Response. Write ("operation failed! "+ Ex. Message); // output
}