views:

39

answers:

1

Hello,

I have a textbox and a button on a form.

I wish to run a query (in Vb.Net) that will produce a query with the IN Values.

Below is an example of my code

myConnection = New SqlConnection("Data Source=sqldb\;Initial Catalog=Rec;Integrated Security=True")
myConnection.Open()
myCommand = New SqlCommand("UPDATE dbo.Recordings SET Status = 0 where RecID in ('" & txtRecID.Text & "') ", myConnection)
ra = myCommand.ExecuteNonQuery()
myConnection.Close()
MsgBox("Done!", _
MsgBoxStyle.Information, "Done")

When i enter a single value it works but when i enter values with commas it throws an error "Conversion failed when converting the varchar value '1234,4567' to data type int."

Could someone please help me to solve this or if there is an alternative way?

Many Thanks

+3  A: 

Try removing the single-quotes you're wrapping the IN values in:

myCommand = New SqlCommand("UPDATE dbo.Recordings SET Status = 0 WHERE RecID IN (" & txtRecID.Text & ") ", myConnection) 
PhilPursglove
This works great! Thank you very much. So what is the single quotes doing? just want to understand it pls
Mo