By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

Working with DataTable Deleted Rows

P: n/a
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());
}
Jul 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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());
}

Jul 26 '07 #2

P: n/a
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:
>
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());
}
Jul 27 '07 #3

P: n/a

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:
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:

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());
}
>
>
Jul 27 '07 #4

P: n/a
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:
>
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:
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:
>
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());
}
Jul 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.