473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Working with DataTable Deleted Rows

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
4 25942

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
3
by: Edward Mostrom | last post by:
I have 2 tables that have a relation between them. The parent table also has an expression in a column that sums the values in the child table. Both tables are hooked up to datagrids. ...
5
by: jurson | last post by:
Hello, I remove row from DataTable. It works ok, the row is removed from collection. It should be marked as 'detached'. Am I right? Then I try to retrieve 'detached' rows using the code shown...
1
by: Gary | last post by:
Hi, I have a DataTable, which will have 2 Columns, one column holds Unique values. I will use DataTable.Select(Unique value) and Filter the Matching rows, After filtering those rows I want...
1
by: Jon | last post by:
Question: does datagrid1.isSelected(i) point to the same row as datatable.row(i).delete after datagrid sorted?? I am using datagrid1.isSelected(i) to identify datatable rows that have been...
5
by: George | last post by:
I have set DataAdapter.AcceptChangesDuringUpdate = true; However, I find that I still need to call AcceptChanges on the associated DataTable, DataTable.AcceptChanges(); Has anyone...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.