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());
} 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());
}
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());
}
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());
}
>
>
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());
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |