本文整理汇总了C#中IBM.Data.DB2.DB2Connection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DB2Connection.BeginTransaction方法的具体用法?C# DB2Connection.BeginTransaction怎么用?C# DB2Connection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBM.Data.DB2.DB2Connection
的用法示例。
在下文中一共展示了DB2Connection.BeginTransaction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteSqlTran
/// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">ArrayList</param>
public static void ExecuteSqlTran(ArrayList sqlList)
{
bool mustCloseConnection = false;
string ConString = System.Configuration.ConfigurationSettings.AppSettings["conInsertDB2"].ToString();
using (DB2Connection conn = new DB2Connection(ConString))
{
conn.Open();
using (DB2Transaction trans = conn.BeginTransaction())
{
DB2Command cmd = new DB2Command();
try
{
for (int i = 0; i < sqlList.Count; i++)
{
string cmdText = sqlList[i].ToString();
PrepareCommand(cmd, conn, trans, CommandType.Text, cmdText, null, out mustCloseConnection);
int val = cmd.ExecuteNonQuery();
}
trans.Commit();
}
catch
{
trans.Rollback();
throw;
}
finally
{
conn.Close();
cmd.Dispose();
}
}
}
}
示例2: queryPrimaryWS
public void queryPrimaryWS()
{
DB2Connection conndb2 = new DB2Connection(globalConnStringDb2);
try
{
conndb2.Open();
DB2Command cmd = conndb2.CreateCommand();
DB2Transaction trans = conndb2.BeginTransaction();
cmd.Transaction = trans;
cmd.CommandText = "" + rtPrimaryWS.Text;
tbPrimWS.Text = cmd.ExecuteScalar().ToString();
string strLog = System.DateTime.Today.ToShortDateString() + " LOG : Ran TA00WB.WORK_SUMMARY Query. " + tbPrimWS.Text + " rows [email protected]";
strLog = strLog.Replace("@", "" + System.Environment.NewLine);
rtLogging.AppendText(strLog);
//logger
string logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using (TextWriter outputFile = new StreamWriter(logFilePath + @"\WBArchiving.txt", true))
{
outputFile.Write(strLog);
}
conndb2.Close();
}
catch (Exception e)
{
tbPrimWS.Text = " ";
MessageBox.Show("An error was encountered during runtime. Please try again.\n\n" + e.GetBaseException().Message, "TA00WB.WORK_SUMMARY Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
string strArchWSLog = System.DateTime.Today.ToShortDateString() + " LOG : Ran TA00WB.WORK_SUMMARY Query. Error occured. No" + tbPrimWS.Text + "rows [email protected]";
strArchWSLog = strArchWSLog.Replace("@", "" + System.Environment.NewLine);
rtLogging.AppendText(strArchWSLog);
}//catch
}
示例3: queryBoundaryDate
public void queryBoundaryDate()
{
DB2Connection conndb2 = new DB2Connection(globalConnStringDb2);
try
{
conndb2.Open();
DB2Command cmd = conndb2.CreateCommand();
DB2Transaction trans = conndb2.BeginTransaction();
cmd.Transaction = trans;
cmd.CommandText = "" + rtCheckBoundary.Text;
tbBoundaryDate.Text = cmd.ExecuteScalar().ToString();
string strBoundaryLog = System.DateTime.Today.ToShortDateString() + " LOG : Ran Archive Boundary Query. Current boundary date is " + tbBoundaryDate.Text + "@" ;
strBoundaryLog = strBoundaryLog.Replace("@", "" + System.Environment.NewLine);
rtLogging.AppendText(strBoundaryLog);
conndb2.Close();
}
catch (Exception e)
{
MessageBox.Show("An error was encountered during runtime. Please try again.\n\n" + e.GetBaseException().Message, "Check Archive Boundary Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}