Here's an example that gets the values that are checked. If its check it does a SELECT statement to see if that value is already in the database. If its not in the database, it inserts that value. In the else statement, which are values that are not checked it deletes that from the database.
Code:
For Each i As ListItem In cblFacilityAssign.Items
If i.Selected Then
Dim SQL As String = "SELECT * FROM [Table] WHERE [ID Column] = " & i.Value & ";"
Dim CMD As New SqlCommand(SQL, _oConn)
Dim oRS As SqlDataReader
oRS = CMD.ExecuteReader()
If Not oRS.Read() Then
oRS.Close()
Dim SQL2 As String = "INSERT INTO A[Table] ([Column1], [Column2], [Column3]) VALUES (" & [Value1] & ", " & [Value2] & ", " & i.Value);"
Dim CMD2 As New SqlCommand(SQL2, _oConn)
CMD2.ExecuteNonQuery()
Else
oRS.Close()
End If
Else
Dim SQL As String = "DELETE FROM [Table] WHERE [ID Column] = " & i.Value & ";"
Dim CMD As New SqlCommand(SQL, _oConn)
CMD.ExecuteNonQuery()
End If
Next
Hope this helps.
Richard