I have a database in SQL 2014, I try to update some field values from 2 list BOX values list, the fisrt variable is a unique Number (1st listbox) which exists in database, second is a fields value where is empty and want to add a value from 2nd list BOX, this code only updates the First record of the table (there are 20 records and adding constantly)
i = 0
Try
Do While 1 = 1
cmd.Connection = SqlConnection1
cmd.CommandType = CommandType.Text
cmd.CommandText = query
cmd.Parameters.AddWithValue("@id2", ListBox1.Items(i).ToString)
cmd.Parameters.AddWithValue("@succes", ListBox2.Items(i).ToString)
i = i + 1
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()
MsgBox("Regisration Success.", MsgBoxStyle.OkOnly, "ss")
Loop
I tried this with the same result like the loop stops to 1st row of list BOX
Dim cmd As New SqlCommand()
query = "update Table_1 set success = @succes where id_2 like @id2"
i = 0
Try
For k = 0 To ListBox1.Items.Count - 1
cmd.Connection = SqlConnection1
cmd.CommandType = CommandType.Text
cmd.CommandText = query
cmd.Parameters.AddWithValue("@id2", ListBox1.Items(k).ToString)
cmd.Parameters.AddWithValue("@succes", ListBox2.Items(k).ToString)
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()
MsgBox("Regisration Success.", MsgBoxStyle.OkOnly, "ss")