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

SqlDataReader problem

Hello,

With my SqlDataReader I select 2 records.

Here is a little bit of my code:
SqlDataReader dr = documents.GetDocuments(ModuleId);

// Load first row into Datareader
if (dr.Read()) {
// Read it!
}

// Load second row into Datareader
if (dr.NextResult()) {
// Read it!
}

dr.Close();

The problem is that the second record dr.NextResult() doesn't work. But
there are two records selected!!!

Why is it not working?

Thanks!
Nov 17 '05 #1
3 4367
If the 2 records are both as a result of one query, then you just need to
call Read again to advance to the next row.

If they are in different record sets, then you need to call Read after
calling NextResult, to advance the next result set to the first row.

"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news4.tilbu1.nb.home.nl...
Hello,

With my SqlDataReader I select 2 records.

Here is a little bit of my code:
SqlDataReader dr = documents.GetDocuments(ModuleId);

// Load first row into Datareader
if (dr.Read()) {
// Read it!
}

// Load second row into Datareader
if (dr.NextResult()) {
// Read it!
}

dr.Close();

The problem is that the second record dr.NextResult() doesn't work. But
there are two records selected!!!

Why is it not working?

Thanks!

Nov 17 '05 #2
call dr.Read() again and not dr.NextResult()

You don't have multiple Select in your Query??
"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news4.tilbu1.nb.home.nl...
Hello,

With my SqlDataReader I select 2 records.

Here is a little bit of my code:
SqlDataReader dr = documents.GetDocuments(ModuleId);

// Load first row into Datareader
if (dr.Read()) {
// Read it!
}

// Load second row into Datareader
if (dr.NextResult()) {
// Read it!
}

dr.Close();

The problem is that the second record dr.NextResult() doesn't work. But
there are two records selected!!!

Why is it not working?

Thanks!

Nov 17 '05 #3
Nope, I understand.

"MS News" <sq**********@hotmail.com> schreef in bericht
news:eK**************@tk2msftngp13.phx.gbl...
call dr.Read() again and not dr.NextResult()

You don't have multiple Select in your Query??
"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news4.tilbu1.nb.home.nl...
Hello,

With my SqlDataReader I select 2 records.

Here is a little bit of my code:
SqlDataReader dr = documents.GetDocuments(ModuleId);

// Load first row into Datareader
if (dr.Read()) {
// Read it!
}

// Load second row into Datareader
if (dr.NextResult()) {
// Read it!
}

dr.Close();

The problem is that the second record dr.NextResult() doesn't work. But
there are two records selected!!!

Why is it not working?

Thanks!


Nov 17 '05 #4

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

Similar topics

3
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
2
by: Matthias S. | last post by:
Hi, I've written a simple app which should just fetch some data from a database and render the results into a ListView. In order to not freeze the GUI, I'm using a BackgroundWorker. The...
7
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
1
by: Arvind P Rangan | last post by:
Hi All, How do you get all the values of a sqldatareader if it contains multiple resultset. Using sqldatareader.nextresult and sqldatareader.read e.g. While sqldatareader.read ' If not...
8
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling:...
4
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't...
4
by: Agnes | last post by:
I got two sub method to check some history record, Now, I found that there is some problem in Sub2() . I think the problem is about the myReader. However, I got no idea to solve it . As Sub2()...
7
by: Web learner | last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows: The name 'dr' does not exist in the current...
3
by: yogarajan | last post by:
hi i am using two sqldatareader. that gives error My code start here SqlConnection conn = new SqlConnection("Data Source=**********;Initial Catalog=****; User Id=****; Password=******"); ...
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...
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...
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,...

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.