DataReader problem...

  • Thread starter Thread starter Bernardo
  • Start date Start date
B

Bernardo

Hi,

I have a datareader, and I want for each record in my
datareader to make an insert in other table, the problem
is that an error occures, it sais that i have to close the
datareder first! :-)

Here is the code
SQL = " SELECT ID_ECRAN ";
SQL = SQL + " FROM MODULO_ECRAN";
SQL = SQL + " WHERE ID_MOD = " + idMod;
cmd = new OleDbCommand(SQL,dbConn);
reader=cmd.ExecuteReader
(System.Data.CommandBehavior.SingleResult);
while(reader.Read())
{
SQL="INSERT INTO PERFIL_MODULO VALUES (" + iperfil
+ "," + idMod + "," + reader["ID_ECRAN"] + ")";
cmd = new OleDbCommand(SQL,dbConn);
cmd.ExecuteNonQuery();
}

Anyone can help?

Thanks a lot
 
That is correct, you must close the reader first before
you can issue another command with the same connection
object. To get around this, you must use a different
connection object for your insert command.

Tu-Thach
 
Back
Top