472,365 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,365 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 25695

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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.