Results 1 to 6 of 6

Thread: ADD + DELETE error

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    13

    ADD + DELETE error

    hi i tried to add and delete a record but i always get an error in my Dataadapter it's something like error in system....dll.
    here is the code i typed
    if anyone could help thanks in advance

    the sqlcommand is
    sqlcommand.commandtext="Select * from Hardware"

    VB Code:
    1. intteller = 0
    2.         If intteller <> -1 Then
    3.  
    4.  
    5.             Dim nieuweRij As DataRow
    6.             Dim mijntabel As New DataTable
    7.             mijntabel = beheerdersDataset.Tables(0)
    8.  
    9.             nieuweRij = beheerdersDataset.Tables(0).NewRow()
    10.  
    11.             nieuweRij.Item("Nr") = txtnr.Text
    12.             nieuweRij.Item("Voornaam") = txtvoornaam.Text
    13.             nieuweRij.Item("Achternaam") = txtachternaam.Text
    14.             nieuweRij.Item("E-mail") = txtemail.Text
    15.             nieuweRij.Item("GSM") = txtgsm.Text
    16.  
    17.             beheerdersDataset.Tables(0).Rows.Add(nieuweRij)
    18.             '   ' here is get my error in the next line
    19.             mijnAdapter.Update(beheerdersDataset)
    20.  
    21.             MsgBox("New Record added to the Database")
    22.  
    23.         End If
    24.  
    25. 'delete
    26.  
    27.         hardwareDataset.Tables(0).Rows(intteller).Delete()
    28.         aantalrec = aantalrec - 1
    29.  
    30.         intteller = 0
    31.         Navigatierecords()
    32.        ' here is get my error in the next line
    33.         mijnAdapter.Update(hardwareDataset)

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: ADD + DELETE error

    Where are your update commands? If you did not specify any, then you need to set a commandbuilder to autogenerate the insert/update/delete commands when you call Update on your dataadapter... you can do it with a simple line of code...
    VB Code:
    1. 'put this line of code (modifying it for your object names) after you create your adapter
    2. Dim MyCmdBuilder As New System.Data.OleDb.OleDbCommandBuilder(MyAdapter)
    Of course, if you arent using an oledb dataadapter, be sure to change it to the type of adapter you are using...

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    13

    Re: ADD + DELETE error

    should i write mycmdbuilder.update(mydataset)

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: ADD + DELETE error

    no you just call your update just like you were doing before... unless you already tried that (which I think you have done)... so if theres still an error, we need the exact error message... put a try/catch block around the update command, and display the error message...

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    13

    Re: ADD + DELETE error

    i tried it your way but i get the error

    http://www.homeandlearn.co.uk/NET/im...ctionError.jpg

    this is the error i get
    Last edited by makaveli19; Dec 31st, 2005 at 09:36 AM.

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: ADD + DELETE error

    have you put try/catch blocks to try to catch the exact error message? Look below for how to do it. Are you using an oledbdataadapter? or a different data adapter? If you are using a SQL data adapter, you have to change it to "System.Data.SqlClient.SqlCommandBuilder"
    VB Code:
    1. Try
    2.     'some code you wish to catch exceptions on...
    3. Catch ex as System.Exception
    4.     Msgbox ex.message
    5. End Try
    Last edited by gigemboy; Dec 31st, 2005 at 04:01 PM.

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