• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 768
  • Last Modified:

The OleDbCommand is currently busy Open, Fetching

Hi,

When I perform a query, followed by another query, the OleDbCommand is still busy.  How should I re-initialize this?

Thanks,
Bob

sql = "SELECT * FROM DeliveryRunDetail WHERE ProcessName='Test';
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
                        
reader = dbCommand1.ExecuteReader();      
while ( reader.Read() )
{
    // do something
}                        

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2'";
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
0
ba272
Asked:
ba272
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
mogunCommented:
Close Reader before executing other SQL commands using the same command object.

Cheers
Mohan
0
 
BlackTigerXCommented:
reader.Close();                    
reader = dbCommand1.ExecuteReader();    
while ( reader.Read() )
{
    // do something
}        
0
 
mogunCommented:
The correct one is

reader = dbCommand1.ExecuteReader();    
while ( reader.Read() )
{
    // do something
}                    

reader.Close();

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2'";
dbCommand1.CommandText = sql;
dbCommand1.ExecuteNonQuery();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bob LearnedCommented:
Creating a new command instance would be better.

Bob
0
 
ba272Author Commented:
Hey Bob,

could you give an example so we're on the same page?

Bob
0
 
Bob LearnedCommented:
Bob,

Do you want to stick with the OleDbDataReader?

Bob
0
 
ba272Author Commented:
for now.  I've got quite a large program created.
0
 
Bob LearnedCommented:
Try this, then:

sql = "DELETE * FROM DeliveryRunDetail WHERE ProcessName='Test2' ";
OleDbCommand dbCommand2 = new OleDbCommand(sql, connection);
dbCommand2.ExecuteNonQuery();

Bob
0
 
ba272Author Commented:
ok
0

Featured Post

Industry Leaders: 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!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now