熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

c#中事務、批量提交、回滾的寫法

2022-06-13   來源: .NET編程 

public void UpdateContactTableByDataSet(DataSet dsstring strTblName)
{
try
{
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlConnection  conn = new SqlConnection(strConnection);
SqlCommand myCommand = new SqlCommand(select * from strTblNameconn);
myAdapterSelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);

connOpen();
SqlTransaction myTrans = connBeginTransaction();
myCommandTransaction = myTrans;

try
{
myAdapterUpdate(dsstrTblName);
myTransCommit();
}
catch(Exception e)
{
try
{
myTransRollback();
}
catch (SqlException ex)
{
if (myTransConnection != null)
{
ConsoleWriteLine(回滾失敗! 異常類型: + exGetType());
}
}
}
finally
{
connClose();
}

}
catch(Exception ex)
{
throw ex;
}
}


From:http://tw.wingwit.com/Article/program/net/201311/15608.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.