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

What rong witht his simple snippit of code?

Hi all,

Whats wrong with the below code? On every loop it seems to be jumping 3
sometimes 4 records. As you can see the SQL query is asking for all records
with no filters. I want to loop each record as I asked. Is there something
with wrong with my code? Thanks in adavnce, Steve.

string str_SQLLayoutsPound = "SELECT * FROM Layouts";.
OleDbCommand obj_SQLLayoutsPound = new OleDbCommand( str_SQLLayoutsPound,
obj_SourceConn );

OleDbDataReader obj_ReaderLayoutsPound = obj_SQLLayoutsPound.ExecuteReader();.

while( obj_ReaderLayoutsPound.Read())
{
string str_CurrentRecord = obj_ReaderLayoutsPound["Name"].ToString();
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200509/1
Nov 17 '05 #1
5 1062
...
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200509/1
Nov 17 '05 #2
"Steve1 via DotNetMonster.com" <u14291@uwe> wrote in message
news:5515b2ac3743e@uwe...
Hi all,

Whats wrong with the below code? On every loop it seems to be jumping 3
sometimes 4 records. As you can see the SQL query is asking for all
records
with no filters. I want to loop each record as I asked. Is there
something
with wrong with my code? Thanks in adavnce, Steve.

string str_SQLLayoutsPound = "SELECT * FROM Layouts";.
OleDbCommand obj_SQLLayoutsPound = new OleDbCommand( str_SQLLayoutsPound,
obj_SourceConn );

OleDbDataReader obj_ReaderLayoutsPound =
obj_SQLLayoutsPound.ExecuteReader();.

while( obj_ReaderLayoutsPound.Read())
{
string str_CurrentRecord = obj_ReaderLayoutsPound["Name"].ToString();
}


The code looks fine to me. What makes you think it is jumping records?

--
Adam Clauss
Nov 17 '05 #3
I've added a watch so when I'm looping through it I can see that the first
record in the loop contains the 3rd record in the database, the next loop its
contains record 6, the next loop its record 10. It seems to be missing out
records. It still does it even if I put an Order By in the SQL query. Any
ideas? Thanks, Steve.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200509/1
Nov 17 '05 #4

"Steve1 via DotNetMonster.com" <u14291@uwe> skrev i en meddelelse
news:55175b885553e@uwe...
I've added a watch so when I'm looping through it I can see that the first
record in the loop contains the 3rd record in the database, the next loop
its
contains record 6, the next loop its record 10. It seems to be missing
out
records. It still does it even if I put an Order By in the SQL query.
Any
ideas? Thanks, Steve.


On the face of it I can't see a problem with your code - maybe you should
post a fuller version of your code.

Are you sure that all the records are not returned? - remember they may come
in a different order than they appear in the database.

Are you sure your "watch" catches all returned results? (Maybe you would be
better served creating a list of the returned names, and then checking them
after the read loop).

Could the problem be you have records which are not committed in the
database (maybe you can "see" them with the program which inserted the
records, but if it did not commit then your reading program won't find
them).

Is it possible the name column is null or empty - what happens then?

Peter
Nov 17 '05 #5
Steve1 via DotNetMonster.com <u14291@uwe> wrote:
I've added a watch so when I'm looping through it I can see that the first
record in the loop contains the 3rd record in the database, the next loop its
contains record 6, the next loop its record 10. It seems to be missing out
records. It still does it even if I put an Order By in the SQL query. Any
ideas? Thanks, Steve.


My guess is that the watch you've added is what's causing it to skip -
if the watch is fetching the next record, that would certainly explain
it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

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

Similar topics

1
by: Jim Benson | last post by:
Hi, I use popen to run a binary executable. A code snippit is below. This part runs fine. I use readline() to catch and print output from the binary to the screen. The system obviously buffers...
2
by: Paul T. Rong | last post by:
Sorry I just lost tracks of a series of posts, so I post my question again, hoping someone can help. Here is codes provided by Jeff Smith > Private Sub Form_Load() > Dim db As...
3
by: Paul T. Rong | last post by:
Do "" and Null both mean nothing?¡¡ If I don't type anything in text box, the its value is Null£¿¡¡Or it is ¡°¡±£¿ I don¡¯ think they are the same, but I don¡¯t know their difference. Thanks.
1
by: Steve1 via DotNetMonster.com | last post by:
Hi all, Why is the last line of this code snippit pulling up with an error? Any help will be appreciated - Thanks, Steve. string str_SQLLayoutsPound = "SELECT * FROM Layouts ORDER BY Name";...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
7
by: Ernest Morariu | last post by:
Hi All! System.Web.UI.Page C# I do not understand what is the Page_Load method. I supose it is an event handler for the Page.Load event, but I cannot find any association between the event...
9
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There...
8
by: Shelly | last post by:
I get an error that the input string is not in the right format. Here is the result: Here is the partial code: Dim sqlConn As New SqlConnection(SqlDataSource1.ConnectionString) Dim query As...
6
by: Joshepmichel | last post by:
package librarySystemV5; import java.sql.*; import java.util.*; public class DatabaseTableViewer { private static final String DB = "mytestdb", ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.