public void UpdateCustomerID(Int32 newId, Int32 oldId, String connectionString)
{
TdConnection cn = null;
TdTransaction tran = null;
try
{
// Open a session to Teradata.
cn = new TdConnection(connectionString);
cn.Open();
// Begin an explicit transaction.
tran = cn.BeginTransaction();
// Create a command to execute DML statements.
TdCommand cmd = cn.CreateCommand();
cmd.Transaction = tran;
// Update the customer table.
cmd.CommandText = String.Format(“Update Customer Set CustomerID = ‘{0}’ "
“where CustomerID = ‘{1}’”, newId, oldId);
cmd.ExecuteNonQuery();
// Update the order table.
cmd.CommandText = String.Format(“Update Order Set CustomerID = ‘{0}’ “
“where CusomerID = ‘{1}’”, newId, oldId);
cmd.ExecuteNonQuery();
// Commit the transaction.
tran.Commit();
tran.Dispose();
tran = null;
// Close the command.
cmd.Dispose();
}
catch(TdException e)
{
if (null != tran)
{
tran.Rollback();
tran.Dispose();
tran = null;
}
}
finally
{
if (null != cn)
{
cn.Close();
cn = null;
}
}
}