c#

位置:IT落伍者 >> c# >> 浏览文章

c#中事务、批量提交、回滚的写法


发布日期:2019年02月26日
 
c#中事务、批量提交、回滚的写法

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;

}

}

上一篇:C#的私有成员的一个有趣的现象

下一篇:C#操作技巧的数据类型之间的转换