473,382 Members | 1,329 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.

sqlDataReader skipping first row in loop

I am looping through a datareader and building a table. However, no matter
what the resultset, the datareader skips the first row of data, then builds
the rest of the resultset.

I have seen this occur in a lot of different places since using .Net.

HAs anyone else found this problem before?

Nov 18 '05 #1
3 4680
Can you show the code? It sounds like you are calling/using something in the
wrong place.

"branton ellerbee" <bl**@sbcglobal.net> wrote in message
news:ld****************@newssvr23.news.prodigy.com ...
I am looping through a datareader and building a table. However, no matter
what the resultset, the datareader skips the first row of data, then
builds
the rest of the resultset.

I have seen this occur in a lot of different places since using .Net.

HAs anyone else found this problem before?


Nov 18 '05 #2
hey

are you looping between the following code

while(DataReader1.Read


common mistake we make is, use

if(DataReader1.Read

and write the looping here
the problem is, if you use "if" then the reader's position is skipped to the first record and thereafter, if you d
some printing or reading stuff, it will read from the second record

hope it helps


----- branton ellerbee wrote: ----

I am looping through a datareader and building a table. However, no matte
what the resultset, the datareader skips the first row of data, then build
the rest of the resultset

I have seen this occur in a lot of different places since using .Net

HAs anyone else found this problem before


Nov 18 '05 #3
If it is because of reading the first record as was explained, you can try a
loop like this:

if(SqlDataReader.Read)
{
do
{
//Do processing of the individual row here
}
while(SqlDataReader.Read);
}
else
{
//NO rows in SqlDataReader
}

With this you can check the existence of rows and still loop them one by
one(including the first one)
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"branton ellerbee" <bl**@sbcglobal.net> wrote in message
news:ld****************@newssvr23.news.prodigy.com ...
I am looping through a datareader and building a table. However, no matter
what the resultset, the datareader skips the first row of data, then builds the rest of the resultset.

I have seen this occur in a lot of different places since using .Net.

HAs anyone else found this problem before?

Nov 18 '05 #4

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

Similar topics

5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
3
by: PeteZ | last post by:
I'm having a problem where I exec a stored procedure (which SELECTs all rows from a table, which has 100 rows) - each row has 8 columns. When I exec the code (see below) I get 8 in...
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...
2
by: Stuart Ferguson | last post by:
I am currently writing my first application in VB.Net and have come accross the following problem, my code is as follows 'Alllocate memory for class objects m_oBusiness = New Validation()...
3
by: dchristjohn | last post by:
I am currently developing a small windows application using Visual Basic via Visual Studio 2005. My database resides on a SQL 2000 server. I have a table with three fields: id (int, Not Null)...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
4
by: nayla | last post by:
I am using 2 SqlDataReader and while(dr.Read()) get only first record and loop stops. its not retriving all of the records but if I comment db1.RunSQLStatement(sql1,out unit_dr); while...
4
by: BibI | last post by:
Hi there, I just started programming with PERL and am trying to put together my first little data manipulation program. I am working on a MAC with OSX. I have a data file with the following...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
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:
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
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.