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. Can only delete numbers in access database

Can only delete numbers in access database

Scheduled Pinned Locked Moved Visual Basic
6 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 can only now delete numbers from acces 2003 and not text. I have tryd this diffrent code, and all of them only delete numbers Eg "888". It cant delete "myname" or "1 myname" only if everthing is numbers

    MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex) & "'"

    MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"

    MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"

    My colums is only set to text and leidraad is the primary key. I don't know if it has to do with my insert to the table, here is the code I am using.

    MyOledbCommand.CommandText = "Insert Into Tblokkies " & "(leidraad,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12) " _
    & "Values (" _
    & "'" & String1 & "', " _
    & "'" & String2 & "', " _
    & "'" & String3 & "', " _
    & "'" & String4 & "', " _
    & "'" & String5 & "', " _
    & "'" & string6 & "', " _
    & "'" & string7 & "', " _
    & "'" & string8 & "', " _
    & "'" & string9 & "', " _
    & "'" & string10 & "', " _
    & "'" & string11 & "', " _
    & "'" & string12 & "', " _
    & "'" & string13 & "')"

    J T 2 Replies Last reply
    0
    • H hendrikbez

      I can only now delete numbers from acces 2003 and not text. I have tryd this diffrent code, and all of them only delete numbers Eg "888". It cant delete "myname" or "1 myname" only if everthing is numbers

      MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex) & "'"

      MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"

      MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"

      My colums is only set to text and leidraad is the primary key. I don't know if it has to do with my insert to the table, here is the code I am using.

      MyOledbCommand.CommandText = "Insert Into Tblokkies " & "(leidraad,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12) " _
      & "Values (" _
      & "'" & String1 & "', " _
      & "'" & String2 & "', " _
      & "'" & String3 & "', " _
      & "'" & String4 & "', " _
      & "'" & String5 & "', " _
      & "'" & string6 & "', " _
      & "'" & string7 & "', " _
      & "'" & string8 & "', " _
      & "'" & string9 & "', " _
      & "'" & string10 & "', " _
      & "'" & string11 & "', " _
      & "'" & string12 & "', " _
      & "'" & string13 & "')"

      J Offline
      J Offline
      Jay Royall
      wrote on last edited by
      #2

      What are you populating ListBox1 with? A collection of objects or are they just strings?

      H 1 Reply Last reply
      0
      • J Jay Royall

        What are you populating ListBox1 with? A collection of objects or are they just strings?

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

        I am usinf this to fill my listbox1

        Do While MyDataReader.Read

                ListBox1.Items.Add(MyDataReader("Leidraad"))
        
                Dim MyItem = ListView1.Items.Add(MyDataReader("Leidraad".ToString))
        
                With MyItem
        
                    .SubItems.Add(MyDataReader("A1").ToString)
                    .SubItems.Add(MyDataReader("A2").ToString)
                    .SubItems.Add(MyDataReader("A3").ToString)
                    .SubItems.Add(MyDataReader("A4").ToString)
                    .SubItems.Add(MyDataReader("A5").ToString)
                    .SubItems.Add(MyDataReader("A6").ToString)
                    .SubItems.Add(MyDataReader("A7").ToString)
                    .SubItems.Add(MyDataReader("A8").ToString)
                    .SubItems.Add(MyDataReader("A9").ToString)
                    .SubItems.Add(MyDataReader("A10").ToString)
                    .SubItems.Add(MyDataReader("A11").ToString)
                    .SubItems.Add(MyDataReader("A12").ToString)
        
                End With
        
            Loop
        

        and these also

        Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

            Dim SqlStr As String
        
        
            SqlStr = "Select \* FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"
        
            'SqlStr = "Select \* from tblokkies where leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"
        
            FillTextBox(SqlStr)
        End Sub
        
        J J 2 Replies Last reply
        0
        • H hendrikbez

          I am usinf this to fill my listbox1

          Do While MyDataReader.Read

                  ListBox1.Items.Add(MyDataReader("Leidraad"))
          
                  Dim MyItem = ListView1.Items.Add(MyDataReader("Leidraad".ToString))
          
                  With MyItem
          
                      .SubItems.Add(MyDataReader("A1").ToString)
                      .SubItems.Add(MyDataReader("A2").ToString)
                      .SubItems.Add(MyDataReader("A3").ToString)
                      .SubItems.Add(MyDataReader("A4").ToString)
                      .SubItems.Add(MyDataReader("A5").ToString)
                      .SubItems.Add(MyDataReader("A6").ToString)
                      .SubItems.Add(MyDataReader("A7").ToString)
                      .SubItems.Add(MyDataReader("A8").ToString)
                      .SubItems.Add(MyDataReader("A9").ToString)
                      .SubItems.Add(MyDataReader("A10").ToString)
                      .SubItems.Add(MyDataReader("A11").ToString)
                      .SubItems.Add(MyDataReader("A12").ToString)
          
                  End With
          
              Loop
          

          and these also

          Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

              Dim SqlStr As String
          
          
              SqlStr = "Select \* FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"
          
              'SqlStr = "Select \* from tblokkies where leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"
          
              FillTextBox(SqlStr)
          End Sub
          
          J Offline
          J Offline
          Jay Royall
          wrote on last edited by
          #4

          OK. Well it all looks fine to me. What I would do is set a breakpoint just before your delete statement and check the value of ListBox1.Items(ListBox1.SelectedIndex) to make sure that you're getting the correct value. Sorry I can't be of more help.

          1 Reply Last reply
          0
          • H hendrikbez

            I can only now delete numbers from acces 2003 and not text. I have tryd this diffrent code, and all of them only delete numbers Eg "888". It cant delete "myname" or "1 myname" only if everthing is numbers

            MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex) & "'"

            MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"

            MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"

            My colums is only set to text and leidraad is the primary key. I don't know if it has to do with my insert to the table, here is the code I am using.

            MyOledbCommand.CommandText = "Insert Into Tblokkies " & "(leidraad,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12) " _
            & "Values (" _
            & "'" & String1 & "', " _
            & "'" & String2 & "', " _
            & "'" & String3 & "', " _
            & "'" & String4 & "', " _
            & "'" & String5 & "', " _
            & "'" & string6 & "', " _
            & "'" & string7 & "', " _
            & "'" & string8 & "', " _
            & "'" & string9 & "', " _
            & "'" & string10 & "', " _
            & "'" & string11 & "', " _
            & "'" & string12 & "', " _
            & "'" & string13 & "')"

            T Offline
            T Offline
            Tom Deketelaere
            wrote on last edited by
            #5

            Use parameters (oledb.oledbparameter) Read up on sql-injunctions

            1 Reply Last reply
            0
            • H hendrikbez

              I am usinf this to fill my listbox1

              Do While MyDataReader.Read

                      ListBox1.Items.Add(MyDataReader("Leidraad"))
              
                      Dim MyItem = ListView1.Items.Add(MyDataReader("Leidraad".ToString))
              
                      With MyItem
              
                          .SubItems.Add(MyDataReader("A1").ToString)
                          .SubItems.Add(MyDataReader("A2").ToString)
                          .SubItems.Add(MyDataReader("A3").ToString)
                          .SubItems.Add(MyDataReader("A4").ToString)
                          .SubItems.Add(MyDataReader("A5").ToString)
                          .SubItems.Add(MyDataReader("A6").ToString)
                          .SubItems.Add(MyDataReader("A7").ToString)
                          .SubItems.Add(MyDataReader("A8").ToString)
                          .SubItems.Add(MyDataReader("A9").ToString)
                          .SubItems.Add(MyDataReader("A10").ToString)
                          .SubItems.Add(MyDataReader("A11").ToString)
                          .SubItems.Add(MyDataReader("A12").ToString)
              
                      End With
              
                  Loop
              

              and these also

              Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

                  Dim SqlStr As String
              
              
                  SqlStr = "Select \* FROM tblokkies WHERE leidraad='" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & "'"
              
                  'SqlStr = "Select \* from tblokkies where leidraad = """ & ListBox1.Items(ListBox1.SelectedIndex) & """"
              
                  FillTextBox(SqlStr)
              End Sub
              
              J Offline
              J Offline
              JC KaNNaN
              wrote on last edited by
              #6

              you can try below below one MyOledbCommand.CommandText = "DELETE * FROM tblokkies WHERE leidraad=" & ListBox1.Items(ListBox1.SelectedIndex).ToString() & ""

              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