Results 1 to 7 of 7

Thread: [RESOLVED] Using Commit / Rollback when using dataset and oledbcommandbuilder

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Resolved [RESOLVED] Using Commit / Rollback when using dataset and oledbcommandbuilder

    Hi,

    I understand how begintrans / commit and rollback work from VB6 but is it possible to use it if I am using the oledbcommandbuilder to populate my dataset and when I do updates. I am writing a routine which updates several tables and I only want this to be completed if all updates were successful. Here is how I populate my dataset:-
    Code:
            sSQL = "SELECT * FROM TO_TRAINING_AND_OPERATING_ITEMS WHERE TO_REFNO = " & Me.tdgMain.Columns("TO_REFNO").Text
            oleDACurrentTOOP = New OleDbDataAdapter
            oleDACurrentTOOP.SelectCommand = New OleDbCommand(sSQL, oleDCData)
            oleDSCurrentTOOP = New DataSet
            oleDACurrentTOOP.Fill(oleDSCurrentTOOP, "TO_TRAINING_AND_OPERATING_ITEMS")
    Many Thanks,

    Jiggy!

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    It is possible, because you are setting the select command object. With the OleDbConnection, you can use the BeginTransaction method and pass that to the commands Transaction property then give the command to the builder.

    Wrap the execution of the command in a try block. If it passed, call Commit on the transaction, otherwise call Rollback.

    EDIT: Link to documentation for the BeginTransaction method and how to use it.
    Last edited by wakawaka; Feb 5th, 2013 at 11:46 AM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    Thanks for the reply, the problem I am facing is I have three tables I need to alter. If any one of the tables fail in update I want to roll back all three. So table 1 was fine, table 2 was fine but table 3 failed so I want to rollback all tables. I almost want to do the begin trans on the connection. I think I need to add all three tables to one dataset and do the begin trans on that dataset then I would only have to do one commit or rollback and if an error occured it would correct all three table. Can anyone give an example on how to do this barring in mind I am using dataadapter and commandbuilders?

    Many Thanks,

    Jiggy!

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    The select is irrelevant... it's the update that's important... you open a connection, begin your transaction, update the first table, update the second table, update the third table, if there are no errors, you commit it... if there are errors you roll it back.

    All of your datatables should be in the same dataset to begin with... you shouldn't have multiple datasets... just one... if even that... you can also get away with multiple datatables, no dataset... but often it's easier to have them all in a dataset if you have more than just a few.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    Yes, the select doesn't mean anything, I just associated with that because it was what I saw first in the code, my bad.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    waka - no worries, my comment was aimed a jiga in the first place....

    going back for a sec...
    I almost want to do the begin trans on the connection.
    Yes... that's what you want... ONE connection, issue a transaction on it, then do your updates...

    I think I need to add all three tables to one dataset and do the begin trans on that dataset then I would only have to do one commit or rollback and if an error occured it would correct all three table.
    mmmm.... no and yes... this is why I cautioned about having multiple datasets in the first place in my original reply... I just wanted to expand on it a little... the transaction would be on the CONNECTION... not the dataset... the connection... so the transaction will affect anything that goes through that connection... you can use the datatables, adaptors and use the Update command... or you can loop through the data and call sprocs... what ever... as long as it goes through that conneciton, it will be part of the transaction.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: Using Commit / Rollback when using dataset and oledbcommandbuilder

    Thanks very much to you both. Makes sense now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width