Results 1 to 5 of 5

Thread: Passing dataadapters...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Passing dataadapters...

    VB Code:
    1. Private myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Path ' Put here the connection string
    2.     Private myConnection As New OleDbConnection(myConnString) 'Create a new connection
    3.  
    4.     Public Function GetDataAdapter(ByVal Query As String) As OleDbDataAdapter
    5.         Dim DA As New OleDbDataAdapter(Query, myConnection)
    6.         Return DA
    7.     End Function
    8.     Public Function ExecuteUpdate(ByRef DA As OleDbDataAdapter, ByRef DS As DataSet, ByRef table As String) As Boolean
    9.         Dim CB As New OleDb.OleDbCommandBuilder(DA)
    10.  
    11.         DA.UpdateCommand = CB.GetUpdateCommand
    12.  
    13.         Try
    14.             DA.Update(DS, table)
    15.             Return True
    16.         Catch e As Exception
    17.             MsgBox(e.ToString)
    18.             Return False
    19.         End Try
    20.     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:
    1. dim DB as new Databaseclass ' this is the class of the above code
    2. dim DA as OleDbDataAdapter
    3. dim DS as new DataSet()
    4.  
    5. DA=DB.GetDataAdapter("SELECT * FROM mytable") ' Get the Dataadapter
    6. DA.Fill(DS,"mytable") ' Fill the DataSet
    7. DS.Tables(0).Rows(0)(0)="kk" ' Just modify an element
    8. dim CB as New OleDbCommandBuilder(DA)
    9.  
    10. 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...

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Same error...

    What else can I try?
    Thx.
    Learn, this is the Keyword...

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    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
  •  



Click Here to Expand Forum to Full Width