D
D13
I'm sure everyone's sick of DataSet, OleDbDataAdapter.Update(), INSERT
INTO etc. etc. questions in this group, but I've been scanning the
usually insta-problem solving Google Groups for hours now and I just
can't seem to find a similar situation to mine.
I'm trying to accomplish something that I thought would be easy
enough:
1. Run a query on a table producing a DataSet of the data I want to
replace
2. Delete all said data
3. Insert another DataSet full of records back into the table
4. Actually have the changes to the database friggin _UPDATE_.
The trick is, and for reasons I won't bother getting into here, I need
to use OleDbCommandBuilder to do the work instead of what otherwise
would be a trivial SQL statement. The step I'm having trouble with is
#3... and well, I suppose #4.
What I'm discovering is that it's extremely difficult to get the
OleDbCommandBuilder to notice when changes have been (are being?) made
to the DataSet. I can manually DataRow.BeginEdit() make changes,
EndEdit() and everything updates fine, so there's no problem with my
peripheral code. I've tried the following ways of getting data from
one DataSet (newDataSet) to the other (dsDBData), all to no avail:
// Row-by-row copy attempts:
foreach (DataRow curRow in newDataSet.Tables["Items"].Rows)
{
dsDBData.Tables["Items"].NewRow();
// #1 dsDBData.Tables["Items"].Rows.Add(curRow);
// ERROR: row is already in another table
// #2 dsDBData.Tables["Items"].Rows.Add(curRow.IndexArray);
// ERROR: OleDbException (?)
// #3 dsDBData.Tables["Items"].ImportRow(curRow);
// RESULT: Data not updated (DataRowState is imported and thus
"Unchanged")
}
// Whole table attempts:
// #4 DataTable tmpTable = dsDBData.Tables["Items"];
// tmpTable = newDataSet.Tables["Items"].Copy();
// RESULT: Data not updated (?)
The closest I seem to get is with #2 wherein an actual UpdateCommand
is built by the OleDbCommandBuilder, but alas a pesky and vague
OleDbException gets thrown.
Apologies for the verbose post on what I originally thought would be
an extremely simply problem to solve. Hopefully there is a quick
answer out there somewhere about something I'm just missing.
Thanks in advance.
INTO etc. etc. questions in this group, but I've been scanning the
usually insta-problem solving Google Groups for hours now and I just
can't seem to find a similar situation to mine.
I'm trying to accomplish something that I thought would be easy
enough:
1. Run a query on a table producing a DataSet of the data I want to
replace
2. Delete all said data
3. Insert another DataSet full of records back into the table
4. Actually have the changes to the database friggin _UPDATE_.
The trick is, and for reasons I won't bother getting into here, I need
to use OleDbCommandBuilder to do the work instead of what otherwise
would be a trivial SQL statement. The step I'm having trouble with is
#3... and well, I suppose #4.
What I'm discovering is that it's extremely difficult to get the
OleDbCommandBuilder to notice when changes have been (are being?) made
to the DataSet. I can manually DataRow.BeginEdit() make changes,
EndEdit() and everything updates fine, so there's no problem with my
peripheral code. I've tried the following ways of getting data from
one DataSet (newDataSet) to the other (dsDBData), all to no avail:
// Row-by-row copy attempts:
foreach (DataRow curRow in newDataSet.Tables["Items"].Rows)
{
dsDBData.Tables["Items"].NewRow();
// #1 dsDBData.Tables["Items"].Rows.Add(curRow);
// ERROR: row is already in another table
// #2 dsDBData.Tables["Items"].Rows.Add(curRow.IndexArray);
// ERROR: OleDbException (?)
// #3 dsDBData.Tables["Items"].ImportRow(curRow);
// RESULT: Data not updated (DataRowState is imported and thus
"Unchanged")
}
// Whole table attempts:
// #4 DataTable tmpTable = dsDBData.Tables["Items"];
// tmpTable = newDataSet.Tables["Items"].Copy();
// RESULT: Data not updated (?)
The closest I seem to get is with #2 wherein an actual UpdateCommand
is built by the OleDbCommandBuilder, but alas a pesky and vague
OleDbException gets thrown.
Apologies for the verbose post on what I originally thought would be
an extremely simply problem to solve. Hopefully there is a quick
answer out there somewhere about something I'm just missing.
Thanks in advance.