How to access deleted row information?

Cricket

Active member
Joined
Jan 6, 2005
Messages
28
Location
Hamilton, ON, Canada
Programming Experience
5-10
I'm trying to loop through deleted rows in a DataTable but it gives me the following error "Deleted row information cannot be accessed through the row."

How do you read the information from a row if it's RowState has been changed to Deleted?

Here is the code.

VB.NET:
 [size=2]
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] dt [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Data.DataTable = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].dtSeriesStandardFeature.GetChanges()

[/size][size=2][color=#0000ff]For[/color][/size][size=2] x [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Integer[/color][/size][size=2] = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] dt.Rows.Count - 1 [/size][size=2][color=#0000ff]Step[/color][/size][size=2] 1

MsgBox(dt.Rows(x).Item("fuid_Series"))

[/size][size=2][color=#0000ff]Next

[/color][/size]
 

ritesh_jain1982

Well-known member
Joined
Jan 10, 2005
Messages
53
Programming Experience
1-3
Hi Cricket,

This will help u .................................
VB.NET:
[color=#0000ff]Dim[/color][size=2] dt [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Data.DataTable = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].dtSeriesStandardFeature.GetChanges()

[/size][size=2][color=#0000ff]If[/color][/size][size=2] dt.Rows(x).RowState = DataRowState.Deleted [/size][size=2][color=#0000ff]Then

[/color][/size][size=2]           MsgBox(dt.Rows(x).Item("fname", DataRowVersion.Original))
[/size][size=2][color=#0000ff]Else[/color][/size]
[size=2]             MsgBox(dt.Rows(x).Item("fname"))[/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]If[/color][/size]
[size=2][color=#0000ff][/color][/size] 
[size=2][color=#0000ff]Regards,[/color][/size]
[size=2][color=#0000ff]Ritesh
[/color][/size]
 

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,461
Programming Experience
10+
I moved it to the ADO.NET forum. Your question is database related, more specifically ADO.NET functionality.

Thank you for posting in the most specific forum in your future posts.
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
lol@neal


here's another tip. this line of code:


VB.NET:
Dim dt As System.Data.DataTable = Me.dtSeriesStandardFeature.GetChanges()
 
 
 
well, getchanges can take a parameter:
 
'get all deleted rows
Dim dt As System.Data.DataTable = Me.dtSeriesStandardFeature.GetChanges(DataRowState.Deleted)

'get all deleted or modified rows
Dim dt As System.Data.DataTable = Me.dtSeriesStandardFeature.GetChanges(DataRowState.Deleted Or DataRowState.Modified)
 
Last edited by a moderator:

alim

Well-known member
Joined
Dec 12, 2005
Messages
89
Location
bangladesh
Programming Experience
3-5
VB.NET:
Dim dt As System.Data.DataTable = Me.dtSeriesStandardFeature.GetChanges(DataRowState.Deleted)
In msdn ... it is sample of code to view deleted rows bt i tried this before.. i haven't got any successful result yet from this line of code....

can any say .. how it will work
 

Paleogirl2003

New member
Joined
Sep 3, 2008
Messages
2
Location
PA
Programming Experience
1-3
I used this:

VB.NET:
DeleteTable = TableToCheck.GetChanges(DataRowState.Deleted)
and it worked for me, just make sure you are not calling

VB.NET:
DataTable.AcceptChanges()
before you check for deleted rows.
 
Top Bottom