473,468 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple queries in a single SQL string

KS
I am passing the following three queries in a string in VS.NET C# class

string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
TABLEC;";
OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
connection object)
DataSet ds = new DataSet;
thisAdapter.Fill(ds);

If the second query fails, the third query doesn't get executed. If the
first one fails (sql +100) the second and third will never be executed.
But i would like the later occuring queries to execute even if the prior
ones have an SQL +100. How do i accomplish this ?

Thanks,
Karthik

Nov 12 '05 #1
3 21867
KS <ks@nospam.net> wrote:
I am passing the following three queries in a string in VS.NET C# class

string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
TABLEC;";
OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
connection object)
DataSet ds = new DataSet;
thisAdapter.Fill(ds);

If the second query fails, the third query doesn't get executed. If the
first one fails (sql +100) the second and third will never be executed.
But i would like the later occuring queries to execute even if the prior
ones have an SQL +100. How do i accomplish this ?


An easy way would be to get the various queries to the point where no +100
is produced in the first place. Then you would have to handle the
situation in your application. If you extend your queries like that, you
should get at least one row - always:

SELECT a
FROM tableA
UNION
SELECT x
FROM TABLE ( VALUES(0) ) AS t(x)
WHERE NOT EXISTS ( SELECT 1
FROM tableA );
<second query in a similar fashion>

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
+100 is not an error, it's a warning. Are you inded seeing that +100
fails the batch?
I recall dimply that there is some CLI parameter (cli.ini file?) that
meedles with how ODBC handles warnings.
You may want to check the CLI docs.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #3
Hello,
what do what to get as a result of these queries. It seems that you
want to build a UNION of these selects, so the select would look like

select A from tableA
union
select B from tableB
union
select C from tableC

as long as A,B and C are of the same datatype.

Joerg

KS <ks@nospam.net> wrote in message news:<cZ*******************@nwrddc02.gnilink.net>. ..
I am passing the following three queries in a string in VS.NET C# class

string sql = "SELECT A FROM TABLEA; SELECT B FROM TABLEB; SELECT C FROM
TABLEC;";
OdbcAdapter thisAdapter = new OdbcAdapter(sql, conn); (conn is my
connection object)
DataSet ds = new DataSet;
thisAdapter.Fill(ds);

If the second query fails, the third query doesn't get executed. If the
first one fails (sql +100) the second and third will never be executed.
But i would like the later occuring queries to execute even if the prior
ones have an SQL +100. How do i accomplish this ?

Thanks,
Karthik

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
1
by: Primo | last post by:
Hello, I am building a data management application with the following processes: Process 1 is a Windows service which uses FileSystemWatcher to monitor a directory. Process 2 opens a file...
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
1
by: JosAH | last post by:
Greetings, Introduction This week we start building Query objects. A query can retrieve portions of text from a Library. I don't want users to build queries by themselves, because users make...
1
by: kadar2itse | last post by:
Hi, I am having multiple update queries inorder to update a records in single table. I am using VB6 and ADODB objects for connecting to DB2 database. I need to run all those queries in a single...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.