sadimul
asked on
Deletting records from two tables
I am trying to delete records from 2 tables using the dataset and trying to update the access data base. I am getting error when I tried to update the 2nd table. Here is the source...
Dim conn As New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.jet.ol edb.4.0;da ta source=C:\Ca_SwTst.mdb"
conn.Open()
Dim Ds As New DataSet
Dim dt As New DataTable
dt.TableName = "Samp1"
Ds.Tables.Add(dt)
Dim da As OleDbDataAdapter
da = New OleDbDataAdapter("select * from emails", conn)
Dim cb1 As New OleDbCommandBuilder(da)
da.Fill(dt)
dt = New DataTable
dt.TableName = "sample2"
Ds.Tables.Add(dt)
da = New OleDbDataAdapter("select * from Cashier", conn)
da.Fill(dt)
Dim cb As New OleDbCommandBuilder(da)
For Each dr As DataRow In Ds.Tables("Samp1").Rows
dr.Delete()
Next
For Each dr As DataRow In Ds.Tables("sample2").Rows
dr.Delete()
Next
da.Update(Ds, "sample2")
da.Update(Ds, "Samp1")
Dim conn As New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.jet.ol
conn.Open()
Dim Ds As New DataSet
Dim dt As New DataTable
dt.TableName = "Samp1"
Ds.Tables.Add(dt)
Dim da As OleDbDataAdapter
da = New OleDbDataAdapter("select * from emails", conn)
Dim cb1 As New OleDbCommandBuilder(da)
da.Fill(dt)
dt = New DataTable
dt.TableName = "sample2"
Ds.Tables.Add(dt)
da = New OleDbDataAdapter("select * from Cashier", conn)
da.Fill(dt)
Dim cb As New OleDbCommandBuilder(da)
For Each dr As DataRow In Ds.Tables("Samp1").Rows
dr.Delete()
Next
For Each dr As DataRow In Ds.Tables("sample2").Rows
dr.Delete()
Next
da.Update(Ds, "sample2")
da.Update(Ds, "Samp1")
What is the exception that you are getting?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
resolved it by updating the table "sample1" with the data adapter before I reteive the data from the 2nd table.
http://msdn.microsoft.com/en-us/library/33y2221y.aspx