Transaction in MS Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using ADO .Net and Access in a VB .Net app. Does MS Access support
Transaction(BeginTransaction, Commit, Rollback)?

Thanks.
 
Hi,


Dim ds As New DataSet

Dim da As OleDbDataAdapter

Dim strConn As String

Dim strSQL As String

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")

DataGrid1.DataSource = ds '.Tables("Categories")

DataGrid1.DataMember = "Categories"

Dim tr As OleDbTransaction

Dim cmdBuild As New OleDbCommandBuilder(da)

Dim cmd As OleDbCommand = cmdBuild.GetUpdateCommand

da.UpdateCommand = cmd

conn.Open()

tr = conn.BeginTransaction

cmd.Transaction = tr

Dim dr As DataRow = ds.Tables("Categories").Rows(0)

Debug.WriteLine(da.UpdateCommand.CommandText)

dr.BeginEdit()

dr.Item("CategoryName") = "Drinks"

dr.EndEdit()

da.Update(ds, "Categories")

tr.Commit()

conn.Close()




Ken
-------------------------

I am using ADO .Net and Access in a VB .Net app. Does MS Access support
Transaction(BeginTransaction, Commit, Rollback)?

Thanks.
 
Hi Ken,

I had tried "dim as OleDbDataAdapter" and "dim as OleDbConnection", but for
some reason they are not recognized as valid. When I hover the mouse over
the statement, it shows for example "Type OleDbConnection is not defined".
Is there anything I need to do prior to this? What could I be missing? Thank
you very much for your help!
 
Be sure you have this statement above the beginning of your Class:

Imports System.Data.OleDb

Then your Dim statements should work..............

james
 
Make sure that at the very top of your class you have the line

imports System.Data.OleDb

That will solve the problem.
 
Back
Top