Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass parameters from 2 listboxes to an SQL table (update the table records)
This code returns error that there is no parameter succes1

VB
Dim query, ss, sd As String
     Dim k, i As Integer
     Dim cmd As New SqlCommand()
     query = "update Table_1 set success  like @succes1 where id_2 like @id2"

     For i = 0 To ListBox1.Items.Count - 1 And ListBox3.Items.Count - 1
        ss = ListBox1.GetItemText(ListBox1.SelectedItems.Item(i).ToString)
         sd = ListBox3.GetItemText(ListBox3.SelectedItems.Item(i).ToString)
                   cmd.Connection = SqlConnection1
         cmd.CommandType = CommandType.Text
         cmd.CommandText = query
                    cmd.Parameters.Item("succes1").Value = sd 'error here
         cmd.Parameters.Item("id2").Value = ss

         Try
             SqlConnection1.Open()
             cmd.ExecuteNonQuery()
             SqlConnection1.Close()

all listbox (1 and 3) rows are selected
Posted

1 solution

The SET clause looks odd. If you want to set the value of success column, try something like
VB
query = "update Table_1 set success = @succes1 where id_2 like @id2"

also you first need to add the parameter into the parameters collection before defining the value for it. I believe that the easiest way is to use AddWithValue[^]
 
Share this answer
 
v3

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