新聞中心
下面將為您介紹如何執(zhí)行多條SQL語句,實(shí)現(xiàn)數(shù)據(jù)庫事務(wù)的方法,供您參考,如果您對SQL語句和事務(wù)感興趣的話,不妨一看,詳細(xì)對您學(xué)習(xí)SQL大有幫助。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比芒市網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式芒市網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋芒市地區(qū)。費(fèi)用合理售后完善,10年實(shí)體公司更值得信賴。
///
/// 執(zhí)行多條SQL語句,實(shí)現(xiàn)數(shù)據(jù)庫事務(wù)。
///
/// 多條SQL語句
public static void ExecuteSqlTran(IList
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
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);
}
}
}
protected void btnOk_Click(object sender, EventArgs e)
{
string upsql = "update 表 set=123 where id=";//省略其他SET
IList
for (int i = 0; i
//下面幾個TextBox省略
if(c.Checked)
{
l.Add("update 表 set='"+tb.Text+"' where id="+ this.DataList1.DataKeys[i].ToString());
}
}
SqlServerHelper.ExecuteSqlTran(l);
}
名稱欄目:通過執(zhí)行多條SQL語句實(shí)現(xiàn)數(shù)據(jù)庫事務(wù)
轉(zhuǎn)載注明:http://fisionsoft.com.cn/article/cdhopis.html


咨詢
建站咨詢
