John Porter
asked on
Can't implement OleDbTransaction
Trying to implement OleDbTransaction Rollback in C#...
Hello,
I am trying to call the Transaction Rollback and Commit methods to Rollback an OleDb transaction to the database in case of a network interuption or other error.
This is my code:
//ConStr defined in properties
OleDbConnection Conn = new OleDbConnection(ConStr);
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbCommandBuilder oleDbCb = new OleDbCommandBuilder(da);
//get a compiler error here saying no constructor defined for OleDbTransaction
OleDbTransaction trans = new OleDbTransaction();
try
{
trans = Conn.BeginTransaction();
cmd = new OleDbCommand(SQL, Conn);
da.SelectCommand = cmd;
da.Update(dataSet1, "Stats");
MessageBox.Show("Your changes have persisted to the Database!");
}//end try
catch
{
trans.Rollback();
}
finally
{
//Close. commit transaction and Dispose called explicitly inside the "finally" block here
Conn.Close();
trans.Commit();
Conn.Dispose();
}
When buiold the solution, I get a compiler error saying no constructor defined for OleDbTransaction.
Is my code correct to rollback or commit a transaction?? How do you define a constructor for a method?
Hello,
I am trying to call the Transaction Rollback and Commit methods to Rollback an OleDb transaction to the database in case of a network interuption or other error.
This is my code:
//ConStr defined in properties
OleDbConnection Conn = new OleDbConnection(ConStr);
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbCommandBuilder oleDbCb = new OleDbCommandBuilder(da);
//get a compiler error here saying no constructor defined for OleDbTransaction
OleDbTransaction trans = new OleDbTransaction();
try
{
trans = Conn.BeginTransaction();
cmd = new OleDbCommand(SQL, Conn);
da.SelectCommand = cmd;
da.Update(dataSet1, "Stats");
MessageBox.Show("Your changes have persisted to the Database!");
}//end try
catch
{
trans.Rollback();
}
finally
{
//Close. commit transaction and Dispose called explicitly inside the "finally" block here
Conn.Close();
trans.Commit();
Conn.Dispose();
}
When buiold the solution, I get a compiler error saying no constructor defined for OleDbTransaction.
Is my code correct to rollback or commit a transaction?? How do you define a constructor for a method?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER