Problem using OdbcCommand

S

scott

Hi all. Thank you for any help that you can offer.



Im making a connection to a mySQL data base.



I then use OdbcCommand to create a query and then execute it using
ExecuteReader. I then use the OdbcDataReader that is returned to get the
results. All is fine until I need to run another query within the current
reader. I get an error message saying "There is already an open DataReader
associated with this Connection which must be closed first".



Does any one know how I can run to readers, one after another ?



Many thanks

Scott.
 
B

Bjorn Abelli

...
Im making a connection to a mySQL data base.

First suggestion, use a MySqlConnecion and MySqlDataReader instead...

http://dev.mysql.com/downloads/connector/net/1.0.html
I then use OdbcCommand to create a query and then execute
it using ExecuteReader. I then use the OdbcDataReader that
is returned to get the results. All is fine until I need
to run another query within the current reader.

You can't use the same reader for two different queries.

You can reuse the reader *variable* for a second reader.
I get an error message saying "There is already an open
DataReader associated with this Connection which must be
closed first".

Does any one know how I can run to readers,
one after another ?

Run the first reader, *close* it, and then use the second one...

MySqlCommand cmd = new MySqlCommand();

// Other things to do, as assigning the connection,etc ...

MySqlDataReader dr = cmd.ExecuteReader();

while (dr.Read() )
{
// Do whatever...
{

dr.Close();

// Assigning a new statement, etc ...

dr = cmd.ExecuteReader();

while (dr.Read() )
{
// Do whatever...
{

dr.Close();

// Bjorn A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

OdbcParameters in SELECT clause 1
ODBC Paramater Problem 1
OdbcCommand exception - MySQL 1
Problem with Oracle database 3
dll 5
Urgent..Please Help... 3
Urgent...Please Help... 3
user control inside placeholder 5

Top