|
-
Sep 21st, 2009, 01:11 PM
#1
Thread Starter
Addicted Member
ado.net update joined dataset
I have been on this for a week, with no luck, I keep getting the same error at the same place. I have gone over all the forums, please give me some help on this...
Basically, I join 3 tables together for reporting, I update one of the tables while reading thru, after I want the updates to stay.
The error is something like "Update requires valid update command on Datarow"
I am in vb.net 9.2, any help is very much appreciated.. thanks
Private OLE_DataAdapter As OleDb.OleDbDataAdapter
Private OLE_DataSet As New DataSet
Private OLE_CN As OleDb.OleDbConnection
private Sub DoStuff()
dim pDT as DataTable
pDT =
Get_Joined_Tables(sQ1, sQ2, sQ3, "2w_1", mTOTAL_PA_FILE, "p3704")
'== do some updates here
Dim DS1 As New DataSet
' Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(OLE_DataAdapter) '** Doesn't work with or without this
DS1 = OLE_DataSet.GetChanges
OLE_DataAdapter.Update(DS1) , "P3704")
OLE_DataSet.AcceptChanges() '*** ERROR HERE
OLE_CN.Close()
end sub
Private function Get Joined_Tables(sQuerys and Tablenames are passed in here) as datatable
Dim OLE_Command As OleDb.OleDbCommand
Dim OLE_DataTable As DataTable = Nothing
Dim sConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE IV;User ID=Admin;Password=;Data Source=" & sFilePath
Try
OLE_CN = New OleDb.OleDbConnection(sConnect)
OLE_CN.Open()
OLE_Command = New OleDb.OleDbCommand(sQuery1, OLE_CN)
OLE_DataAdapter = New OleDb.OleDbDataAdapter(OLE_Command)
OLE_DataAdapter.Fill(OLE_DataSet, sTableName1)
OLE_Command = New OleDb.OleDbCommand(sQuery2, OLE_CN)
OLE_DataAdapter = New OleDb.OleDbDataAdapter(OLE_Command)
OLE_DataAdapter.Fill(OLE_DataSet, sTableName2)
OLE_Command = New OleDb.OleDbCommand(sQuery3, OLE_CN)
OLE_DataAdapter = New OleDb.OleDbDataAdapter(OLE_Command)
OLE_DataAdapter.Fill(OLE_DataSet, sTableName3)
Dim col(1) As DataColumn
'== set a primary key to table for updating ( doesn't work with or without this)
col(0) = OLE_DataSet.Tables(2).Columns(0)
OLE_DataSet.Tables(2).PrimaryKey = col
OLE_DataSet.Relations.Add("ds", OLE_DataSet.Tables(sTableName1).Columns("Value"), OLE_DataSet.Tables(sTableName2).Columns("Value"), False)
OLE_DataSet.Relations.Add("ds2", OLE_DataSet.Tables(sTableName2).Columns("Value"), OLE_DataSet.Tables(sTableName3).Columns("Value"), False)
Return OLE_DataSet.Tables(0)
end function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|