SQL/OldDbCommand object and parameters

  • Thread starter Thread starter Steve Barnett
  • Start date Start date
S

Steve Barnett

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
 
Steve said:
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.
 
Sericinus hunter said:
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.
 
Steve said:
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.
 
Back
Top