VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Save Data Using IsolationLevel

by Gehan Fernando (47 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Wed 2nd May 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Save Data Using IsolationLevel

API Declarations


Imports System.Data.OleDb

Private OleCon As System.Data.OleDb.OleDbConnection
Private OleCom As System.Data.OleDb.OleDbCommand

Rate Save Data Using IsolationLevel




        Dim IsInTran As Boolean = False
        Dim OleTrn As System.Data.OleDb.OleDbTransaction

        Try
            OleCon = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Visual Studio.net Code Samples\Check_Security\Test.mdb")
            OleCon.Open()

            OleTrn = OleCon.BeginTransaction(IsolationLevel.ReadCommitted)

            IsInTran = True

            OleCom = New System.Data.OleDb.OleDbCommand()
            OleCom.CommandText = "INSERT INTO Employees " & _
                                 "(EmployeeName,EmployeeAddress,EmployeeAge,City) " & _
                                 "VALUES " & _
                                 "('" & TxtName.Text & "','" & TxtAddress.Text & _
                                 "'," & Int16.Parse(TxtAge.Text) & ",'" & _
                                 TxtCity.Text & "')"

            OleCom.CommandType = CommandType.Text
            OleCom.Connection = OleCon
            OleCom.Transaction = OleTrn

            OleCom.ExecuteNonQuery()
            OleTrn.Commit()

            OleTrn.Dispose()
            OleCom.Dispose()
            OleCon.Dispose()

            Return True
        Catch ex As Exception
            If IsInTran = True Then
                OleTrn.Rollback()
                OleTrn.Dispose()
                OleCom.Dispose()
                OleCon.Dispose()
            End If
            Return False
        End Try

    End Function

    Private Function RetReviewData() As DataSet

        Try
            Dim OleCon As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Visual Studio.net Code Samples\Check_Security\Test.mdb")
            OleCon.Open()
            Dim OleCom As New System.Data.OleDb.OleDbCommand("SELECT * FROM Employees", OleCon)
            OleCom.CommandType = CommandType.Text
            Dim OleAdap As New System.Data.OleDb.OleDbDataAdapter(OleCom)
            Dim OleDSet As New DataSet()
            OleAdap.Fill(OleDSet)
            OleCon.Dispose()
            Return OleDSet
        Catch ex As Exception
            Throw ex
        End Try

    End Function

    Private Sub BtnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click

        Try
            If UpdateData() = True Then
                MessageBox.Show("Update Successfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
                TxtName.ResetText()
                TxtAddress.ResetText()
                TxtAge.ResetText()
                TxtCity.ResetText()
                DGrid.DataSource = RetReviewData.Tables(0)
            Else
                MessageBox.Show("Not Update Successfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            DGrid.DataSource = RetReviewData.Tables(0)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

Download this snippet    Add to My Saved Code

Save Data Using IsolationLevel Comments

No comments have been posted about Save Data Using IsolationLevel. Why not be the first to post a comment about Save Data Using IsolationLevel.

Post your comment

Subject:
Message:
0/1000 characters