I have a list box on my form which is auto populate by an SQL statement as below:
If Not IsPostBack Then
connect.ConnectionString = Constr
Dim query5 As String = "SELECT ComplaintTo FROM Complaint2 GROUP BY ComplaintTo HAVING (COUNT(Complaint_ID) < 5)"
Dim ds As New DataSet
Dim i As Integer
Try
connect.Open()
Dim da As New SqlDataAdapter(query5, connect)
da.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
ListBox1.Items.Add(ds.Tables(0).Rows(i).Item(0))
Next
connect.Close()
Catch ex As Exception
End Try
End If
Now from the data that has been populate in the list box, i want to update a column in a table where the corresponding value matches.
meaning if a value "xx@hotmail.com" is in the listbox, i should update the column status of xx@hotmail.com in a table automatically
if there are 10 records, all those 10 records should be updated automatically without clicking on a button.. below is my code which im trying to without much success
Sub Desactive_Status_Tech()
connect.ConnectionString = Constr
Dim qryUpdateComplaint As String = "update Tech4 set Status='Not Active' where Email=@email"
Dim cmd As New SqlCommand(qryUpdateComplaint, connect)
cmd.Parameters.AddWithValue("@email", ListBox1)
Try
connect.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
connect.Close()
End Try
End Sub
can someone plz help me