Using an IN clause in Vb.net to save something to the database using SQL

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-09-30T10:27:34Z Indexed on 2012/11/26 5:04 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql