Intercept UPDATEs and change to INSERTs

  • Thread starter Thread starter Fred Morrison
  • Start date Start date
F

Fred Morrison

What's the best strategy for intercepting updated rows in
a DataSet (let's assume only one DataTable) and turning
them into INSERT's (I'll tweak a Date/Time stamp to insure
they are new rows that don't violate any constraints)? I
don't need code examples, just advice from those with
experience. If it matters, my app is 3-tiered
(Presentation, Business, Data layers).
 
Hi Fred,

Below is the snippet.
I actually implement DataTable.RowChanged event when I remove the row and
re-add it so it is marked as Added at the end.


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

private void Form1_Load(object sender, System.EventArgs e)
{

dt = new DataTable();

dt.Columns.Add("tubo", typeof(int));

dt.Rows.Add(new object[]{1});

dt.AcceptChanges();

dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);

dt.Rows[0][0] = 2;

Console.WriteLine(dt.Rows[0].RowState);

}

private void dt_RowChanged(object sender, DataRowChangeEventArgs e)

{

if (e.Action == DataRowAction.Change && e.Row != null && e.Row.RowState !=
DataRowState.Unchanged)

{

object[] o = e.Row.ItemArray;

dt.Rows.Remove(e.Row);

dt.LoadDataRow(o, false);

}

}
 
Back
Top