Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OleDbDataReader messed up after being passed as parameter

Posted on 2007-11-23
7
Medium Priority
?
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 48

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

597 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