472,972 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 software developers and data experts.

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 1095
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dent | last post by:
I am having a problem with a program that I wrote to format an Excel spreadsheet. I wrote the program on a WinXP/Office XP/Visual Studio .NET 2003 computer. I am using late-binding. When I try...
5
by: Greg | last post by:
Hi, I have been unable to resolve this error message: Object Ref not set to an instance of an object. The issue is that I cannot determine which object reference is causing the problem. ...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
0
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
0
by: Roman | last post by:
I'm trying to create the form which would allow data entry to the Client table, as well as modification and deletion of existing data rows. For some reason the DataGrid part of functionality stops...
0
by: Elliot M. Rodriguez | last post by:
I implemented a very small, basic data access layer for my web application. It works just fine, except for this one bug. One of my methods returns an abstracted dataset. To accomodate X number of...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
1
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return...
3
by: Steve Barnett | last post by:
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.