What rong witht his simple snippit of code?

  • Thread starter Thread starter Steve1 via DotNetMonster.com
  • Start date Start date
S

Steve1 via DotNetMonster.com

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();
}
 
Steve1 via DotNetMonster.com said:
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?
 
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.
 
Steve1 via DotNetMonster.com said:
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
 
Steve1 via DotNetMonster.com said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top