Solved

OleDbDataReader messed up after being passed as parameter

Posted on 2007-11-23
7
354 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 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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