|
-
May 4th, 2003, 11:09 AM
#1
Thread Starter
Hyperactive Member
Passing dataadapters...
VB Code:
Private myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Path ' Put here the connection string
Private myConnection As New OleDbConnection(myConnString) 'Create a new connection
Public Function GetDataAdapter(ByVal Query As String) As OleDbDataAdapter
Dim DA As New OleDbDataAdapter(Query, myConnection)
Return DA
End Function
Public Function ExecuteUpdate(ByRef DA As OleDbDataAdapter, ByRef DS As DataSet, ByRef table As String) As Boolean
Dim CB As New OleDb.OleDbCommandBuilder(DA)
DA.UpdateCommand = CB.GetUpdateCommand
Try
DA.Update(DS, table)
Return True
Catch e As Exception
MsgBox(e.ToString)
Return False
End Try
End Function
This is the code I have in my project.
The problem is (again) I can't update the database... In a form I write:
VB Code:
dim DB as new Databaseclass ' this is the class of the above code
dim DA as OleDbDataAdapter
dim DS as new DataSet()
DA=DB.GetDataAdapter("SELECT * FROM mytable") ' Get the Dataadapter
DA.Fill(DS,"mytable") ' Fill the DataSet
DS.Tables(0).Rows(0)(0)="kk" ' Just modify an element
dim CB as New OleDbCommandBuilder(DA)
DA.UpDate(DS,"mytable") ' Update with changes, BUT here I get the error.
The error says there's an error in the UPDATE instruction, but I'm sure it's right!!! The error is the same when I call DB.ExecuteUpdate(....). But if I put all the code in the DB class (load dataadapter, fill dataset, modify, update) I Update the DB regularly.
What is this ??!?!?   
Learn, this is the Keyword...
-
May 4th, 2003, 12:01 PM
#2
Frenzied Member
In the GetDataAdapter function instantiate the oleCommandBuilder there then pass it to the dataAdapter, then return your dataAdapter.
Dont gain the world and lose your soul
-
May 4th, 2003, 01:06 PM
#3
Thread Starter
Hyperactive Member
Same error...
What else can I try?
Thx.
Learn, this is the Keyword...
-
May 4th, 2003, 02:18 PM
#4
Frenzied Member
Look in the fields names and see if they contain any reserved word.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 4th, 2003, 04:33 PM
#5
Thread Starter
Hyperactive Member
Lunatic3, you, my save!! It is! I read a post here, I think about 1 week ago!!! Do NOT use reserved words!!! Short memory 
Thanks a lot guys!
Learn, this is the Keyword...
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
|