• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 833
  • Last Modified:

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?
0
Saxitalis
Asked:
Saxitalis
2 Solutions
 
Bob LearnedCommented:
No constructor, it gets created from the BeginTransaction call from the connection object.

    OleDbTransaction trans = null;

Bob
0
 
SaxitalisAuthor Commented:
This helped Bob and Hites! Thanks much - sax
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now