Save Data Using IsolationLevel
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
(1(1 Vote))
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
Save Data Using IsolationLevel Comments
No comments yet — be the first to post one!
Post a Comment