Results 1 to 10 of 10

Thread: Can Transaction be used with recordsets?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    10000 light years away
    Posts
    143

    Can Transaction be used with recordsets?

    Hi All,

    Can BeginTrans and CommitTrans be used with ADO recordsets as well? I am using 2 recordsets with rs.AddNew and rs.Update. Can I use BeginTrans and CommitTrans in this case? Or is it applicable only for Conn.Execute?

    All help will be apreciated.

    Thanks,

    Binish
    I was gratified to be able to answer promptly. I said I don't know!

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Can Transaction be used with recordsets?

    recordsets dont need those lines of code, if you add a new record, you can directly say, rs.Addnew then supply the values to the fields. this can be done provided your recordset is directly connected to a single table in your database only and not a result of a stored procedure
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Can Transaction be used with recordsets?

    I hope BeginTrans and CommitTrans can be used only with the Connections and not with Recordsets...just before your addnew put BeginTrans and after the update put CommitTrans...
    VB Code:
    1. Conn.BeginTrans
    2. rs.AddNew
    3. '.....
    4. rs.Update
    5. Conn.CommitTrans
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    10000 light years away
    Posts
    143

    Re: Can Transaction be used with recordsets?

    In my case, I need to make sure either both my recordsets are updated after AddNew or None. Typically a case where I need to use a transaction
    I was gratified to be able to answer promptly. I said I don't know!

  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Can Transaction be used with recordsets?

    VB Code:
    1. Conn.BeginTrans
    2. rs.AddNew 'Your 1st Recordset
    3. '.....
    4. rs.Update
    5.  
    6. rs1.AddNew 'Your 2nd Recordset
    7. '....
    8. rs1.Update
    9. Conn.CommitTrans
    This will make sure both the recordsets are updated, else none...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    10000 light years away
    Posts
    143

    Re: Can Transaction be used with recordsets?

    Quote Originally Posted by ganeshmoorthy
    I hope BeginTrans and CommitTrans can be used only with the Connections and not with Recordsets...just before your addnew put BeginTrans and after the update put CommitTrans...
    VB Code:
    1. Conn.BeginTrans
    2. rs.AddNew
    3. '.....
    4. rs.Update
    5. Conn.CommitTrans
    I will definitely try this. Hope that will solve the problem
    I was gratified to be able to answer promptly. I said I don't know!

  7. #7
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Can Transaction be used with recordsets?

    have you checked my other post too...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    10000 light years away
    Posts
    143

    Re: Can Transaction be used with recordsets?

    Quote Originally Posted by ganeshmoorthy
    VB Code:
    1. Conn.BeginTrans
    2. rs.AddNew 'Your 1st Recordset
    3. '.....
    4. rs.Update
    5.  
    6. rs1.AddNew 'Your 2nd Recordset
    7. '....
    8. rs1.Update
    9. Conn.CommitTrans
    This will make sure both the recordsets are updated, else none...

    I will try this and come back. Thanks a lot!
    I was gratified to be able to answer promptly. I said I don't know!

  9. #9
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: Can Transaction be used with recordsets?

    you should put an error handler incase an error occur on any of the recordset
    error_handler:
    debug.print rs.status
    debug.print rs1.status
    conn.rollbacktrans
    err.clear
    adRecOK 0 The record was successfully updated.
    adRecNew 1 The record is new.
    adRecModified 2 The record was modified.
    adRecDeleted 4 The record was deleted.
    adRecUnmodified 8 The record wasn't modified.
    adRecInvalid &H10 The record wasn't saved because its bookmark is invalid.
    adRecMultipleChanges &H40 The record wasn't saved because it would affect multiple records.
    adRecPendingChanges &H80 The record wasn't changed because it refers to a pending insert.
    adRecCanceled &H100 The record wasn't saved because the operation was canceled.
    adRecCantRelease &H400 The record wasn't saved because of existing record locks.
    adRecConcurrencyViolation &H800 The record wasn't saved because optimistic concurrency was in use.
    adRecIntegrityViolation &H1000 The record wasn't saved because it would violate integrity constraints.
    adRecMaxChangesExceeded &H2000 The record wasn't saved because there were too many pending changes.
    adRecObjectOpen &H4000 The record wasn't saved because of a conflict with an open storage object.
    adRecOutOfMemory &H8000 The record wasn't saved because of an out-of-memory error.
    adRecPermissionDenied &H10000 The record wasn't saved because the user had insufficient permissions.
    adRecSchemaViolation &H20000 The record wasn't saved because it doesn't match the structure of the database.
    adRecDBDeleted &H40000 The record had already been deleted from the database.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    10000 light years away
    Posts
    143

    Re: Can Transaction be used with recordsets?

    That was really cool. Thanks a lot!
    I was gratified to be able to answer promptly. I said I don't know!

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