?
Solved

OleDbDataReader messed up after being passed as parameter

Posted on 2007-11-23
7
Medium Priority
?
355 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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