Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cannot update or delete access database

Cannot update or delete access database

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestionannouncement
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hendrikbez
    wrote on last edited by
    #1

    I am trying to update and delete ,but get this error code now, it did work before. error code == "There is no row at position -1" My update code

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim cb As New OleDb.OleDbCommandBuilder(da)
    
        ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
        ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text
        ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text
        ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text
        ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text
        ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text
        ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text
        ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text
        ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text
        ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text
        ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text
        ds.Tables("Blokkies").Rows(inc).Item(12) = txtA10.Text
        ds.Tables("Blokkies").Rows(inc).Item(13) = txtA10.Text
    
        da.Update(ds, "Blokkies")
    
        MsgBox("Register verander")
    
    End Sub
    

    I did try to use this, but still get same error

    If Not IsDBNull(ds.Tables("Blokkies").Rows(inc).Item("luidraad")) Then
    ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
    End If

    My delete code

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        If MessageBox.Show("Is jy seker jy wil die register verwyder?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
    
            MsgBox("Register is nie verwyder nie")
            Exit Sub
    
        End If
    
        Dim cb As New OleDb.OleDbCommandBuilder(da)
    
        ds.Tables("Blokkies").Rows(inc).Delete()
        maxrows = maxrows - 1
    
        inc = 0
        NavigateRecords()
        da.Update(ds, "Blokkies")
    
    End Sub
    
    D _ 2 Replies Last reply
    0
    • H hendrikbez

      I am trying to update and delete ,but get this error code now, it did work before. error code == "There is no row at position -1" My update code

      Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

          Dim cb As New OleDb.OleDbCommandBuilder(da)
      
          ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
          ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text
          ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text
          ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text
          ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text
          ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text
          ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text
          ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text
          ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text
          ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text
          ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text
          ds.Tables("Blokkies").Rows(inc).Item(12) = txtA10.Text
          ds.Tables("Blokkies").Rows(inc).Item(13) = txtA10.Text
      
          da.Update(ds, "Blokkies")
      
          MsgBox("Register verander")
      
      End Sub
      

      I did try to use this, but still get same error

      If Not IsDBNull(ds.Tables("Blokkies").Rows(inc).Item("luidraad")) Then
      ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
      End If

      My delete code

      Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

          If MessageBox.Show("Is jy seker jy wil die register verwyder?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
      
              MsgBox("Register is nie verwyder nie")
              Exit Sub
      
          End If
      
          Dim cb As New OleDb.OleDbCommandBuilder(da)
      
          ds.Tables("Blokkies").Rows(inc).Delete()
          maxrows = maxrows - 1
      
          inc = 0
          NavigateRecords()
          da.Update(ds, "Blokkies")
      
      End Sub
      
      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Check the value of the variable inc and check that the dataset is not empty.

      जय हिंद

      H 1 Reply Last reply
      0
      • D dan sh

        Check the value of the variable inc and check that the dataset is not empty.

        जय हिंद

        H Offline
        H Offline
        hendrikbez
        wrote on last edited by
        #3

        sorry, how do you check the value and that the daataset is not empty

        D 1 Reply Last reply
        0
        • H hendrikbez

          sorry, how do you check the value and that the daataset is not empty

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          You will need to debug the code. Then use Add Watch or quick watch to find the value.

          जय हिंद

          1 Reply Last reply
          0
          • H hendrikbez

            I am trying to update and delete ,but get this error code now, it did work before. error code == "There is no row at position -1" My update code

            Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

                Dim cb As New OleDb.OleDbCommandBuilder(da)
            
                ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
                ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text
                ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text
                ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text
                ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text
                ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text
                ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text
                ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text
                ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text
                ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text
                ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text
                ds.Tables("Blokkies").Rows(inc).Item(12) = txtA10.Text
                ds.Tables("Blokkies").Rows(inc).Item(13) = txtA10.Text
            
                da.Update(ds, "Blokkies")
            
                MsgBox("Register verander")
            
            End Sub
            

            I did try to use this, but still get same error

            If Not IsDBNull(ds.Tables("Blokkies").Rows(inc).Item("luidraad")) Then
            ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text
            End If

            My delete code

            Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

                If MessageBox.Show("Is jy seker jy wil die register verwyder?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
            
                    MsgBox("Register is nie verwyder nie")
                    Exit Sub
            
                End If
            
                Dim cb As New OleDb.OleDbCommandBuilder(da)
            
                ds.Tables("Blokkies").Rows(inc).Delete()
                maxrows = maxrows - 1
            
                inc = 0
                NavigateRecords()
                da.Update(ds, "Blokkies")
            
            End Sub
            
            _ Offline
            _ Offline
            _Damian S_
            wrote on last edited by
            #5

            You don't appear to be setting the value of inc anywhere before you try to use it.

            Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

            H 1 Reply Last reply
            0
            • _ _Damian S_

              You don't appear to be setting the value of inc anywhere before you try to use it.

              Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

              H Offline
              H Offline
              hendrikbez
              wrote on last edited by
              #6

              I am new to databse, I don't know how to set the value in the code yet. I did try this, but it is not working If inc <> -1 Then ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text ds.Tables("Blokkies").Rows(inc).Item(12) = txtA11.Text ds.Tables("Blokkies").Rows(inc).Item(13) = txtA12.Text da.Update(ds, "Blokkies") MsgBox("Register verander") End If

              modified on Thursday, March 19, 2009 2:27 AM

              C 2 Replies Last reply
              0
              • H hendrikbez

                I am new to databse, I don't know how to set the value in the code yet. I did try this, but it is not working If inc <> -1 Then ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text ds.Tables("Blokkies").Rows(inc).Item(12) = txtA11.Text ds.Tables("Blokkies").Rows(inc).Item(13) = txtA12.Text da.Update(ds, "Blokkies") MsgBox("Register verander") End If

                modified on Thursday, March 19, 2009 2:27 AM

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                You're entering a contest to see who can write the most illegible code ?

                Christian Graus Driven to the arms of OSX by Vista.

                H 1 Reply Last reply
                0
                • C Christian Graus

                  You're entering a contest to see who can write the most illegible code ?

                  Christian Graus Driven to the arms of OSX by Vista.

                  H Offline
                  H Offline
                  hendrikbez
                  wrote on last edited by
                  #8

                  now what is the best why do wright this code, I am new and want to get this right.

                  C 1 Reply Last reply
                  0
                  • H hendrikbez

                    now what is the best why do wright this code, I am new and want to get this right.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Like I said, your best option is to let your client know you're not the right man for the job. Buy some books and read them. Learn how to program before having clients.

                    Christian Graus Driven to the arms of OSX by Vista.

                    1 Reply Last reply
                    0
                    • H hendrikbez

                      I am new to databse, I don't know how to set the value in the code yet. I did try this, but it is not working If inc <> -1 Then ds.Tables("Blokkies").Rows(inc).Item(1) = TxtLuidraad.Text ds.Tables("Blokkies").Rows(inc).Item(2) = txtA1.Text ds.Tables("Blokkies").Rows(inc).Item(3) = txtA2.Text ds.Tables("Blokkies").Rows(inc).Item(4) = txtA3.Text ds.Tables("Blokkies").Rows(inc).Item(5) = txtA4.Text ds.Tables("Blokkies").Rows(inc).Item(6) = txtA5.Text ds.Tables("Blokkies").Rows(inc).Item(7) = txtA6.Text ds.Tables("Blokkies").Rows(inc).Item(8) = txtA7.Text ds.Tables("Blokkies").Rows(inc).Item(9) = txtA8.Text ds.Tables("Blokkies").Rows(inc).Item(10) = txtA9.Text ds.Tables("Blokkies").Rows(inc).Item(11) = txtA10.Text ds.Tables("Blokkies").Rows(inc).Item(12) = txtA11.Text ds.Tables("Blokkies").Rows(inc).Item(13) = txtA12.Text da.Update(ds, "Blokkies") MsgBox("Register verander") End If

                      modified on Thursday, March 19, 2009 2:27 AM

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #10

                      I'm sorry, I thought you were someone else. Break it down into steps. Write code that checks that a table of that name exists, that it has rows, etc. Then step through the code in the debugger.

                      Christian Graus Driven to the arms of OSX by Vista.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups