Many thanks for both excellent responses (both maked yes as helpful). On the
second question, I just found that the following also works for getting a
table with the original versions of the deleted rows.
//The DataView (dv) now contains only deleted rows
DataView dv = new DataView( TableWithDeletedRows,
null, null, DataViewRowState.Deleted);
//The new DataTable (dt) now contains the original versions of the deleted
rows.
DataTable dt = dv.ToTable();
Thanks again for all the help!
Randy
"Adrian Voicu" wrote:
Quote:
>
The following line of code will pretty much give you a table with all the
deleted rows.
>
DataTable delRowsTable = mTTSDataSet1.Table1.GetChanges(DataRowState.Delete d);
>
Using this you can parse each row and display the original contents of a
cell by specifing a column as in the previous example. You could use this
information to build a query or record data that was destroyed.
>
The following code
>
DataRow dr = delRowsTable.Rows[i][DataRowVersion.Original].ToString())
>
does not work because "DataRowVersion.Original" is supposed to be the name
of a column in the ith deleted row. The result will be the value in the ith
row and the column you specified that you are then trying to assign to a
DataRow object.
>
Adrian.
--
[Please mark my answer if it was helpful to you]
>
>
>
>
"randy1200" wrote:
>
Quote:
Yes, that was very helpful. Thanks!
Any suggestion on how to extract the entire original row? The following
variation doesn't quite work.
DataRow dr = deletedRows.Rows[i][DataRowVersion.Original].ToString());
Thanks again,
Randy
"Adrian Voicu" wrote:
Quote:
>
You could try something like this:
>
DataTable deletedRows = mTTSDataSet1.Table1.GetChanges(DataRowState.Delete d);
for (int i = 0; i < deletedRows.Rows.Count; i++)
{
Console.WriteLine("Deleted: " + deletedRows.Rows[i]["Column2",
DataRowVersion.Original].ToString());
}
>
Adrian.
--
[Please mark my answer if it was helpful to you]
>
>
>
>
"randy1200" wrote:
>
I'm working in Visual Studio 2005 and C#.
I have a DataTable with many rows. The user can delete a row. After the row
is deleted, I'd like to column values for the deleted row, but any attempt to
access column values results in the following exception:
{"Deleted row information cannot be accessed through the row."}
My understanding is that a copy of the original row is still in there. Any
suggestions on how to access??
Thanks,
Randy
DataViewRowState dvrs = DataViewRowState.Deleted;
DataRow[] rows = MyDataSet.MyDataTable.Select("", "", dvrs);
for (int i = 0; i < rows.Length; i++)
{
DataRow dr = rows[i];
Console.WriteLine(dr["Column42"].ToString());
}