weird connection error

F

fanor

Hi guys,


I have 2 data adapters da1 and da2, 1 connection con1, and one data set
ds1. I use the same connection for all this data adapters.

when I change from one record to other on the table JOBS under da1 it
trigger one event. In this event, I have a code like



System.Windows.Forms.BindingManagerBase bc;

bc = this.BindingContext[this.ds1, "jobs"];



this.ds1.WorkEmp.Clear();

if (bc.Count>0)
{
System.Data.DataRow drv;

drv = this.ds1.jobs.Rows[bc.Position];
this.daWorkEmp.SelectCommand.Parameters["njob"].Value=Convert.ToInt16(drv["njob"]);
try
{
this.daWorkEmp.Fill(this.ds1.WorkEmp); // ERROR HAPPENS HERE
}
catch (Exception e3)
{
MessageBox.Show(e3.ToString());
return ;
}
}



I got this error message


"System.invalidOperationException: there is already an open DataReader
associated with this connection which must closed first"



WorkEmp.SelectCommand is a like

SELECT b.firstname, b.lastname, a.empid, a.njob, b.empid AS Expr1 FROM
WorkOn a INNER JOIN employee b ON a.empid = b.empid WHERE (a.njob = ?)


I'm missing something???

I use the same logic in other modules with other tables and it works.




I appreciate any help, thanks
 
C

Cor Ligthert

Fanor,

Do you maybe have a "connection open" somewhere in your program. When you
are using this kind of single datatable fills there is no need for using
that. The dataadapter does that for you.

When you fill datatables in a row in a dataset than you can use the
connection open, however have to add a finally block in your try to be sure
that it is closed forever than after the operation (I assume it is not an
Access database).

I hope this helps?

Cor
 

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


Top