Solved

OleDbDataReader messed up after being passed as parameter

Posted on 2007-11-23
7
348 Views
Last Modified: 2008-09-12
Hello, in my code I have the following situation:

-I open an OleDbDataReader (using ExecuteReader() from an OleDbCommand);
-call the method .Read() on the OleDbDataReader;
-I invoke a function, passing the OleDbDataReader as a parameter.

Now, if I try to access an .Item(<item name>) of my OleDbDataReader I get an Exception. Using the debugger, I can see that the value .Item(<item name>) is fine before I call the function, is no longer fine in the context of the function.

Why is like this? How can I fix this?
0
Comment
Question by:Emanuele_Ciriachi
  • 4
  • 2
7 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20341553
Hi Emanuele_Ciriachi,

Why are you using the Read() method? If you can do away with that, it will work fine, as you have noticed.

Regards,

Wayne
0
 
LVL 1

Author Comment

by:Emanuele_Ciriachi
ID: 20341614
Are you saying that I should use Read after passing it as a parameter? I don't understand, is there something about how Read() works that I don't understand?

I invoke Read() before passing the DataReader to a function. After the Read and before the function call I can use it. After the function call, I can't.
0
 
LVL 1

Author Comment

by:Emanuele_Ciriachi
ID: 20341648
Wait, I found it - apparently, my OleDbDataReader becomes messed up after I execute the following, completely unrelated, code:

frm.Visible = true

somewhere else. GO FIGURE.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20343256
It's not possible for the form Visible change to affect the DataReader. The reason I asked if you used the Read method before passing it to the function is, when there is only one row returned, the Read method reads that single row, and any subsequent reads will return false, and cause an error. If you are calling the Read method to determine if there are any rows returned, you  should instead use the HasRows() function.
0
 
LVL 1

Accepted Solution

by:
Emanuele_Ciriachi earned 0 total points
ID: 20343285
In my case, it was... I found out why: I was creating that form through reflection, and somehow its Form_Load method was called in the moment the form became visible..! One of the Form_Load events involved a function that uses and closes the shared OleDbDataReader of the class I'm using, and this created the trouble.

So I'm afraid this question was asked on an error which was different from the one I advertised at first, and that I resolved by myself.
Sorry for wasting some of your time.
0
 
LVL 1

Author Comment

by:Emanuele_Ciriachi
ID: 20344537
Thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now