SQL Parameterized Queries with IN statement

F

Fred

Hi,

When trying the following code :

[...]
oCmd = "SELECT MyField FROM MyTable WHERE MyID IN (@IDList)"
MyCommand = New SqlCommand(oCmd, oConn)
MyCommand.Parameters.Add(New SqlParameter("@IDList",
SqlDbType.NVarChar))
MyCommand.Parameters("@IDList").Value = "5611,1332"
[...]

I've got the following error :
Syntax error converting the nvarchar value '5611,1332' to a column of
data type int

MyID type is SqlDbType.Int
@IDList is a comma separated int values list (=> String). Is this type
correct or should I use another one ? Is there a particular syntax to
assign a parameter in that kind of query ?

Thanks
Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top