473,394 Members | 1,722 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,394 software developers and data experts.

ExecuteReader - Two select statments- returns only the first statment result

Hello,

I am using Microsoft.Practices.EnterpriseLibrary.Data.

I am running the following

sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT
var3 FROM table2 WHERE var2 IN (4,5,6)";

IDataReader dataReader = db.ExecuteReader(dbCommandWrapper); while
(dataReader.Read()) {

The problem is that the dataReader holds only the data from table1 i.e.
the first select statment.

Do you have any idea how to work it out?

Nov 17 '05 #1
5 3080
You have to call .NextResult to access the result set for the second query.

You can also use the UNION operator in your SQL to get a union of the
results both queries return, if they are getting two different pieces of the
same data.

<or****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Hello,

I am using Microsoft.Practices.EnterpriseLibrary.Data.

I am running the following

sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT
var3 FROM table2 WHERE var2 IN (4,5,6)";

IDataReader dataReader = db.ExecuteReader(dbCommandWrapper); while
(dataReader.Read()) {

The problem is that the dataReader holds only the data from table1 i.e.
the first select statment.

Do you have any idea how to work it out?

Nov 17 '05 #2
You need to call the next result, like this:
// Get the reader.
using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
{
// Cycle while there are results.
do
{
// Cycle while there are records.
while (dataReader.Read())
{

}
} while (dataReader.NextResult());
}

I didn't run this through a compiler, but you should get the general
idea for the syntax. The key here is the call to NextResult. Of course,
putting it in a loop like this isn't going to be the right way to do this,
since you will probably need specific processing of each result.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
IDataReader dataReader = db.ExecuteReader(dbCommandWrapper); while
(dataReader.Read()) {

<or****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com... Hello,

I am using Microsoft.Practices.EnterpriseLibrary.Data.

I am running the following

sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT
var3 FROM table2 WHERE var2 IN (4,5,6)";

IDataReader dataReader = db.ExecuteReader(dbCommandWrapper); while
(dataReader.Read()) {

The problem is that the dataReader holds only the data from table1 i.e.
the first select statment.

Do you have any idea how to work it out?

Nov 17 '05 #3

Thank you for your quick post.
I works. don't know why I have missed it.

New problem:
Do you know how to avoid the exception?

I am running in the inner, read, loop and check for data from both
statments. At each do while iteration loop I have one exception.

At the end I have the correct data but since exception is expsnsive I
want to avoid it all together.

Thank you
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
oren,

You shouldn't get an exception. Without you giving the details (or how
you ultimately called the code), it's impossible to tell.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"oren cs" <or****@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

Thank you for your quick post.
I works. don't know why I have missed it.

New problem:
Do you know how to avoid the exception?

I am running in the inner, read, loop and check for data from both
statments. At each do while iteration loop I have one exception.

At the end I have the correct data but since exception is expsnsive I
want to avoid it all together.

Thank you
*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #5
I am retrieving the data explicitly like this:
dataReader["a_max"];
dataReader["b_max"];
In the first I have loop the dataReader will throw and exception for
dataReader["b_max"];
in the second on dataReader["a_max"];

I can avoid it by knowing exactly what are the column names in each
iteration or using GetValues()

Nov 20 '05 #6

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

Similar topics

0
by: Hans Maurer | last post by:
>Description: We're running our current TTS application with MySQL (on Unix). All database, table and column names are in lower-case. However, we need to access this database with a new...
0
by: dregier | last post by:
attached is my full query that I am currently working on: Declare @counterday1 int Declare @counterday2 int set @counterday1 = '20' set @counterday2 = '629' Declare @CounterMin07_01 float...
7
by: Weaver | last post by:
In another database that I've used, I found the FOR SELECT syntax handy. It allows a stored procedure to perform actions for each record returned by the select statement. I can't find the...
0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
0
by: amir | last post by:
Hallo Ihr Experten, ich habe die Frage schon mal gepostet. Habe aber leider immer keine passende Antwort erhalten :( Vielleicht sollte ich noch sagen, dass ich keine Lösung auf VB-Basis suche!...
2
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
4
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
1
by: fniles | last post by:
I am using OLEDBDataReader to read from an Access database. I have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new...
5
by: Givisiez | last post by:
Hi I'm programming a windows application. I store values on a SQL- database. Now I've a problem reading the values stored. I want to read a whole column from a table. I tried my SQL Command in...
2
by: murugavelmsc | last post by:
Hi, In Visual studio 2008, i got a error "ExecuteReader: Connection property has not been initialized" . So guide me protected void Button1_Click(object sender, EventArgs e) { ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.