473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem using OdbcCommand

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.
Nov 19 '05 #1
1 2615

"scott" wrote...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But...
3
by: Thubaiti | last post by:
hi there.. I have a problem with this code... any help please ? SQL: CREATE TABLE member (sn NUMBER(6), nickname VARCHAR2(30), password VARCHAR2(30));
4
by: Dakkar | last post by:
I write a program for connecting to mysql database and read the values that i want from the database so i wrote my code like this RegistryKey uo =...
2
by: Reddy | last post by:
Hi, Once after inserting a record into a table is there a more efficient way of retreiving the id(autonumber field) value in the following example. Using a SQL server database. con.Open() ...
1
by: TomislaW | last post by:
This is the code: OdbcConnection conn = new OdbcConnection(m_ConnectionString); OdbcDataAdapter adapter = new OdbcDataAdapter(); adapter.SelectCommand = new OdbcCommand("spUser", conn); ...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
1
by: sbreytberg | last post by:
Hi all, I am a newbie at dotnet. Been going through someone else's code and here's a problem: I am loading a csv file into the database. When there's more than one record, it works fine, but...
6
by: Aleyna[] | last post by:
Hi all, I wanted to connect an old DBASE file (I don't know the exact version) but I could not make it at all. I couldn't find a way to execute sql statements on db file using c#. The...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.