DbDataReader drops results

I have a scenario were my data clears out after connecting to an excel spreadsheet using DbDataReader.  Below is the sample code.  So if I mouse over datareader to the results view I see records at first but then disappears if I pause and does not return any records in the loop.
string Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=excelFile;Extended Properties=Excel 8.0;";

using (OleDbConnection conn = new OleDbConnection(Conn))
        {
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [sheet$]", conn);
            conn.Open();

            using (DbDataReader datareader = cmd.ExecuteReader())
            {

            }

Open in new window

ws11Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
You got it into a reader object  and you are not doing anything inside the pause. DataReader object gets closed once the using block is finished and you would not be able to see records.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guru_samiCommented:
---> then disappears if I pause and does not return any records in the loop.
Where is your loop...or code you are trying to read data from?
0
ws11Author Commented:
It will not loop it just goes through what the loop contains one time despite how many records I have.  I have used this before but not with an excel file.
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ws11Author Commented:
If I stop my trace at using (DbDataReader datareader = cmd.ExecuteReader())  the results view shows my column count and all my records so it has the data but if I wait go back and look again it will clear the ienumerable.
0
ws11Author Commented:
See images.  Image1 is first view then Image2 is after.  The ienumerable is clearing its self.  But it should not do this when it loops until the loop is finish.  At least that is what I would expect.
Image1.jpg
Image2.jpg
0
ws11Author Commented:
So I guess something like this would continue to loop...

foreach (DbDataRecord record in reader)
0
guru_samiCommented:
to loop through the records you will need to use Read method like shown here:
while(datareader.Read())
{
//get values..
}

Check this: http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson04.aspx
0
ws11Author Commented:
Sorry I did not follow your initial post but figured it out that I needed to go row by row.  I thought that was what ienumerables enumeration was all about.  Any comments on the enumeration aspect would be greatly appreciated.
0
ws11Author Commented:
Yes I have that already sorry for not posting that part.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.