473,382 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1106
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.