470,867 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,867 developers. It's quick & easy.

SQL/OldDbCommand object and parameters

I'm trying to do things properly and use OleDbCommand objects and parameters
to build me SQL queries. In the past, I've always built them as strings...
I'm now stuck. I have an SQL statement of the form:

Select <field names> FROM <table name> WHERE field_1 IN ( values list )

How do I specify the "values list" as a parameter to a Command object? I've
use Parameters to specify individual values, but never a list of values like
this.

Thanks
Steve
Jun 8 '06 #1
3 1038
Steve Barnett wrote:
I'm trying to do things properly and use OleDbCommand objects and parameters
to build me SQL queries. In the past, I've always built them as strings...
I'm now stuck. I have an SQL statement of the form:

Select <field names> FROM <table name> WHERE field_1 IN ( values list )

How do I specify the "values list" as a parameter to a Command object? I've
use Parameters to specify individual values, but never a list of values like
this.


You cannot. SQL does not support arrays. You need either to resort to
dynamic SQL or, better, to re-write WHERE clause using OR instead of IN.
Jun 8 '06 #2
"Sericinus hunter" <se*****@flash.net> wrote in message
news:Lj******************@newssvr14.news.prodigy.c om...
Steve Barnett wrote:
I'm trying to do things properly and use OleDbCommand objects and
parameters to build me SQL queries. In the past, I've always built them
as strings... I'm now stuck. I have an SQL statement of the form:

Select <field names> FROM <table name> WHERE field_1 IN ( values
list )

How do I specify the "values list" as a parameter to a Command object?
I've use Parameters to specify individual values, but never a list of
values like this.


You cannot. SQL does not support arrays. You need either to resort to
dynamic SQL or, better, to re-write WHERE clause using OR instead of IN.


I see, thanks. Unfortunately, I cannot always predict how many items will
appear in the IN list, which means I can't pre-setup OR statements.

Looks like I'll have to go back to my old way of doing things.
Jun 8 '06 #3
Steve Barnett wrote:
"Sericinus hunter" <se*****@flash.net> wrote in message
news:Lj******************@newssvr14.news.prodigy.c om...
Steve Barnett wrote:
I'm trying to do things properly and use OleDbCommand objects and
parameters to build me SQL queries. In the past, I've always built them
as strings... I'm now stuck. I have an SQL statement of the form:

Select <field names> FROM <table name> WHERE field_1 IN ( values
list )

How do I specify the "values list" as a parameter to a Command object?
I've use Parameters to specify individual values, but never a list of
values like this.

You cannot. SQL does not support arrays. You need either to resort to
dynamic SQL or, better, to re-write WHERE clause using OR instead of IN.


I see, thanks. Unfortunately, I cannot always predict how many items will
appear in the IN list, which means I can't pre-setup OR statements.

Looks like I'll have to go back to my old way of doing things.


Dynamic SQL should suffice in such a case.
Jun 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dent | last post: by
14 posts views Thread by stic | last post: by
reply views Thread by Elliot M. Rodriguez | last post: by
3 posts views Thread by Adriano | last post: by
1 post views Thread by leslie_tighe | last post: by
3 posts views Thread by Steve Barnett | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.