Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
Experts Most Trusted Topic
exception there is already an open datareader associated with this connection w
exception there is already an open datareader associated with this connection w ¬†using -'c#,mysql'
I have below code and I am getting exception:
¬†¬†There is already an open DataReader associated with this Connection which must be closed first.
I am using Visual Studio 2010/.Net 4.0 and MySQL for this project. Basically I am trying to run another SQL statement while using data reader to do my other task. I am getting exception at line cmdInserttblProductFrance.ExecuteNonQuery();
SQL = "Select * from tblProduct";
MySqlConnection myConnection = new MySqlConnection(cf.GetConnectionString());
MySqlCommand myCommand = new MySqlCommand(SQL, myConnection);
MySqlDataReader myReader = myCommand.ExecuteReader();
¬†¬†¬†¬†int i = 0;
¬†¬†¬†¬†// Always call Read before accessing data.
¬†¬†¬†¬†¬†¬†¬†¬†if (myReader["frProductid"].ToString() == "") //there is no productid exist for this item
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†strInsertSQL = "Insert Into tblProduct_temp (Productid) Values('this istest') ";
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†MySqlCommand cmdInserttblProductFrance = new MySqlCommand(strInsertSQL, myConnection);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†cmdInserttblProductFrance.ExecuteNonQuery(); //<=====THIS LINE THROWS "C# mySQL There is already an open DataReader associated with this Connection which must be closed first."
Oct 6, 2015
to add a comment.
Related Hot Questions
Government Jobs Opening