remove listbox item if it is already on database
This code will remove items to be displayed on a listbox if already inputed on databse:
On DataBound event of listbox control insert this code:
Dim mypk As String
Dim i As Integer
For i = 0 To myListBox.Items.Count - 1
If i = myListBox.Items.Count Or i > myListBox.Items.Count Then
Else
mypk = myListBox.Items(i).ToString()
command = New Data.SqlClient.SqlCommand("SELECT * FROM MYTABLE WHERE MYPK = '" & mypk & "'", connection)
reader = command.ExecuteReader()
If reader.Read() Then
myListBox.Items.RemoveAt(i)
i = i - 1
Else
End If
reader.Close()
End If
Next