Can only delete numbers in access database
-
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 & "')" -
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 & "')"What are you populating ListBox1 with? A collection of objects or are they just strings?
-
What are you populating ListBox1 with? A collection of objects or are they just strings?
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
-
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
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.
-
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 & "')"Use parameters (oledb.oledbparameter) Read up on sql-injunctions
-
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