Solved

OleDbDataReader messed up after being passed as parameter

Posted on 2007-11-23
7
351 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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