Downloads
Search: 

Transactions made easy
Thursday, January 26th, 2012 at 19h58
A helper class for transaction enabled data write. It can be used as is, on backend databases which support transactions e.g. SQL server, Oracle and yes Access too. ...
General information
URL:TxnWrite.zip
Downloads:838
File type:Freeware
Rating: Rate this entry
Description
A helper class for transaction enabled data write.

Methods:

  • SetParameterValue - method supplies values to parameters in a sql query
  • ExecuteNonQuery - for use w/ SQLs that need to return the number of rows affected e.g. INSERT ...
  • ExecuteScalar - returns a value from a query SELECT COUNT(*) ...
  • ExecuteSql - for use w/ SQLs that return a DataTable
  • Commit() - Attempts to write everything from the transaction scope
  • Rollback() - Prevents everything in the transaction scope from being written to the underlying tables
  • IsCommitted- Property indicates save status:
    • True - indicates a successful commit operation.
    • False - indicates transaction roll back or uncommitted transactions.
Sample usage in the code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim shipperNames As String() = {"First Shipping Company", "Second Shipping Company", "Third Shipping Company", Nothing}

        Using rs As New Framework_Code.TxnWrite("NorthwindConnectionString")
            Try
                For i As Byte = 0 To 3 ' Change this to 2 for a successful commit because CompanyName cannot be NULL/Nothing.
                    rs.SetParameterValue("CompanyName", shipperNames(i))
                    rs.ExecuteNonQuery("INSERT INTO Shippers (CompanyName) VALUES (@CompanyName)")
                Next
                rs.Commit()
            Catch ex As Exception
                rs.Rollback()
            End Try
            Label1.Text = IIf(rs.IsCommitted, "Committed", "Rolledback")
        End Using

    End Sub
Created by
Denny Jacob
UT brotherhood is a great place to turn to when you are in dire need of a programming clue. It is been my experience that at least 3 people respond to each problem I post. "Downloads" has a wealth of great VCXs and ideas to equip a good VFP programmer for better. God bless UT.

Comments

Add a comment

More downloads created from this member
Wednesday, March 14th, 2007 at 09h30
This is a class to send emails with minimum effort while allowing for multiple To, Cc, Bcc and Attachments. You will need to also modify your web.config to work with your SMTP provider i.e. the settings you would use on your Outlook Account settings.