Link to home
Start Free TrialLog in
Avatar of John Porter
John PorterFlag for United States of America

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?
ASKER CERTIFIED SOLUTION
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Porter

ASKER

This helped Bob and Hites! Thanks much - sax