Click here to Skip to main content
15,895,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
VB
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
VB
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()

               'Successlbl.show()
               MsgBox("Regisration Success.", MsgBoxStyle.OkOnly, "ss")
Posted
Updated 5-Jul-15 21:33pm
v2
Comments
Andy Lanng 6-Jul-15 4:13am    
You haven't told us where the problem is. Do you get an error? which line?
Thanks ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900