Detached rows in a datatable

P

Peter Borremans

Hello,

Is there any possibility to access the detached rows in a datatable/dataset?

Thank you,

Peter
 
C

Cor

Hi Peter,

A lot of methods, but a dataset is this

dataset1.tables(0).rows(0).item(0)

This is the first item in the first row in the first table from your
dataset.

All items are reachable by setting those indexes.

I hope that was what you where looking for?

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Peter,
My understanding is: if they are detached, then there is no way to access
them, unless you still have a variable that references them.

As they are not attached to anything yet to reach them... The row will have
a reference to the table, but the table does not yet have a reference to the
row.... The reference to the row (from the table) is made when you add the
row to the DataTable.Rows collection.

Hope this helps
Jay
 
C

Cor

Hi Peter,

You got me curious, what do you mean with a detached rows in a dataset, I
thought you where talking about rows in a detached XML file, but now when I
see Jay B's answer I become curious.

Cor
 
P

Peter Borremans

A datarow in a dataset (Rows collection of a datatable ) can have the
following rowstates:
1.Added
2.Deleted
3.Detached
4.Modified
5.Unchanged

1. A row has this rowstate when you add it to the rows collection...
2. Rowstate for removed rows.
4. Rowstate for rows that where edited.
5. Nothing happened to rows of this type (initial rowstate).
3. Detached rows: A row has this rowstate when it's about to be added or
removed from the rows collection of a datatable.
But, rows with this rowstate are not a part of the rows collection. So,
I don't have a reference to access them...
Example when this occurs: 'A user adds a line in a datagrid, but the
cursor is still in the new line, as long as the cursor stays there, the
rowstate of this row is detached, when you change row in the datagrid the
rowstate will become 'Added'.

I hope this makes it a bit clearer...

Peter.
 
C

Cor

Hi Peter,

I see now what you mean, and that is as Jay B. said an unreferenced row.

As far as I know is this is almost the last place you can get a deleted and
a removed row.
(It can after this also in the rowdeleted).

\\\
AddHandler ds.Tables(0).RowDeleting, _
New DataRowChangeEventHandler(AddressOf Row_Deleting)
///

The sender is the removed or deleted row.

Keep in mind that a removed row will normaly not be updated in the database
if you use a dataadapter.update, it is only gone in the datagrid, a deleted
row will be deleted using that methode.

I hope this helps a little bit?

Cor
 
J

Julian Hershel

I have a question related to rowstates. Is the Deleted rowstate used when I
remove a row or when I delete a row? Since Delete only marks the row for
deletion, I keep thinking about how the rowstate reflects it.

Thank you.

Julian
 
J

Jay B. Harlow [MVP - Outlook]

Julian,
When you use DataRow.Delete the rowstate is changed to Deleted, this is what
informs the DataAdapter to delete the actual row in your actual database
table.

When you use DataRowCollection.Remove the DataRow is detached from the
DataTable. Because the row is not Detached it cannot modify your actual
database table.

Hope this helps
Jay
 
C

Cor

Only a little thing
When you use DataRowCollection.Remove the DataRow is detached from the
DataTable. Because the row is not Detached it cannot modify your actual
database table.

I am almost sure Jay means
Because the row is not attached it cannot modify your actual database table.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Doh!
As Cor stated, the following should read:
Because the row is not Detached it cannot modify your actual
database table.

Because the row is NOW detached it cannot modify your actual database table.

Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top