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

DataReader

Hi!

I am trying to create a DataReader in .Net 2003, retrieving data from an
Access backend db. In the code below, when I put a breakpoint within
the While...Read() loop, the datareader returns five records (which is
correct). However, when I simply run the program without the
breakpoint, only one record is being returned. Is there something I'm
missing???? The connection state is "Open", so I'm not sure why all
records aren't being returned.

Dim intUpdateEMGsCount As Integer = 0
Dim cnnUpdateEMGs As OleDbConnection = New
OleDbConnection(IMUX_Globals.connBE.ConnectionStri ng)
Dim cmdUpdateEMGs As OleDbCommand = New OleDbCommand("SELECT " & _
"lngEMGId, " &
_

"IIf(IsNull([CountETB]),0, [CountETB]) AS TotalETB, " & _

"IIf(IsNull([CountEMRPS]),0, [CountEMRPS]) AS TotalEMRPS, " & _

"IIf(IsNull([CountRTT]),0, [CountRTT]) AS TotalRTT, " & _

"IIf(IsNull([CountDCH]),0, [CountDCH]) AS TotalDCH " & _
"FROM " & _
"(((tblOrig_EMG
LEFT JOIN qgrpCountETB ON tblOrig_EMG.strEMG = qgrpCountETB.strEMG) LEFT
JOIN qgrpCountDCH ON tblOrig_EMG.strEMG = qgrpCountDCH.strEMG) LEFT JOIN
qgrpCountEMRPS ON tblOrig_EMG.strEMG = qgrpCountEMRPS.strEMG) LEFT JOIN
qgrpCountRTT ON tblOrig_EMG.strEMG = qgrpCountRTT.strEMG", _
cnnUpdateEMGs)

cnnUpdateEMGs.Open()
odrUpdateEMGs =
cmdUpdateEMGs.ExecuteReader(CommandBehavior.CloseC onnection)
Console.WriteLine("State: " & cnnUpdateEMGs.State.ToString)
If odrUpdateEMGs.HasRows Then
While odrUpdateEMGs.Read()
intNumRecs += 1
End While
End If
odrUpdateEMGs.Close()
Console.WriteLine("Num Records: " & intNumRecs.ToString)

TIA,

DaveS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
2 1550
Cor
Hi Dave,

Just a thougth, I was looking to that long SQL script you are using and that
needs knowledge of your database. (Besides that I think nobody here is
intrested to evaluate it, that is more for the ado.net newsgroup).

Maybe you can test your code with a simple Select of one item in one table.

I asume it is not the "Select" that is not working but the logic.

When it does work with that simple select, it is your "Select".

I hope this helps a little bit?

Cor
I am trying to create a DataReader in .Net 2003, retrieving data from an
Access backend db. In the code below, when I put a breakpoint within
the While...Read() loop, the datareader returns five records (which is
correct). However, when I simply run the program without the
breakpoint, only one record is being returned. Is there something I'm
missing???? The connection state is "Open", so I'm not sure why all
records aren't being returned.

Dim intUpdateEMGsCount As Integer = 0
Dim cnnUpdateEMGs As OleDbConnection = New
OleDbConnection(IMUX_Globals.connBE.ConnectionStri ng)
Dim cmdUpdateEMGs As OleDbCommand = New OleDbCommand("SELECT " & _
"lngEMGId, " &
_

"IIf(IsNull([CountETB]),0, [CountETB]) AS TotalETB, " & _

"IIf(IsNull([CountEMRPS]),0, [CountEMRPS]) AS TotalEMRPS, " & _

"IIf(IsNull([CountRTT]),0, [CountRTT]) AS TotalRTT, " & _

"IIf(IsNull([CountDCH]),0, [CountDCH]) AS TotalDCH " & _
"FROM " & _
"(((tblOrig_EMG
LEFT JOIN qgrpCountETB ON tblOrig_EMG.strEMG = qgrpCountETB.strEMG) LEFT
JOIN qgrpCountDCH ON tblOrig_EMG.strEMG = qgrpCountDCH.strEMG) LEFT JOIN
qgrpCountEMRPS ON tblOrig_EMG.strEMG = qgrpCountEMRPS.strEMG) LEFT JOIN
qgrpCountRTT ON tblOrig_EMG.strEMG = qgrpCountRTT.strEMG", _
cnnUpdateEMGs)

cnnUpdateEMGs.Open()
odrUpdateEMGs =
cmdUpdateEMGs.ExecuteReader(CommandBehavior.CloseC onnection)
Console.WriteLine("State: " & cnnUpdateEMGs.State.ToString)
If odrUpdateEMGs.HasRows Then
While odrUpdateEMGs.Read()
intNumRecs += 1
End While
End If
odrUpdateEMGs.Close()
Console.WriteLine("Num Records: " & intNumRecs.ToString)

Nov 20 '05 #2
Cor,

Thanks for your comments.

Just before creating the DataReader (whose Command is based on
tblOrig_EMG), I populated tblOrig_EMG with an INSERT query. My guess is
that this query hadn't completed by the time the DataReader was being
created -- when I moved the code for this DataReader to a different
spot, it worked just fine. Go figure...

TIA,

DaveS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

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

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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?
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
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.