L
Leonid Raiz
Group,
I am relatively new to ADO.NET and am trying to figure out how to do the
following. I established OleDbConnection and now need to read all records
from one of the tables. For every record in first table I need to insert
records into other table. A simpleminded approach would be
....
readCmd.CommandText = "SELECT * FROM ReadTable";
writeCmd.CommandText = "INSERT INTO WriteTable WHERE col1 = ? AND col2 = ?";
OleDbDataReader reader = read.ExecuteReader();
while( reader.Read() )
{
....// prepare record data for WriteTable
writeCmd.ExecuteNonQuery();
}
Unfortunately such code raises exceptions when wrteCmd.ExecuteNonQuery() is
invoked because the reader is still open. How to I code this type of
operation correctly? Or is there a different strategy to achieve what I want
in a relatively efficient way? I would rather avoid the performance overhead
of bringing in entire ReadTable into memory at once.
Thanks for your help,
- LR
I am relatively new to ADO.NET and am trying to figure out how to do the
following. I established OleDbConnection and now need to read all records
from one of the tables. For every record in first table I need to insert
records into other table. A simpleminded approach would be
....
readCmd.CommandText = "SELECT * FROM ReadTable";
writeCmd.CommandText = "INSERT INTO WriteTable WHERE col1 = ? AND col2 = ?";
OleDbDataReader reader = read.ExecuteReader();
while( reader.Read() )
{
....// prepare record data for WriteTable
writeCmd.ExecuteNonQuery();
}
Unfortunately such code raises exceptions when wrteCmd.ExecuteNonQuery() is
invoked because the reader is still open. How to I code this type of
operation correctly? Or is there a different strategy to achieve what I want
in a relatively efficient way? I would rather avoid the performance overhead
of bringing in entire ReadTable into memory at once.
Thanks for your help,
- LR