dataset.getchanges fails to return changes

  • Thread starter Thread starter Parsley
  • Start date Start date
P

Parsley

Hi All

I'm experiencing the problem of dataset.getchanges
returning unmodified rows only :

myDs.ReadXml("c:\Parsley.xml", xmlReadMode.Auto)
For Each t In myDs.Tables
For Each r In t.Rows
If r.Item("Deleted").ToString = "True" Then
r.Delete()
Exit For
End If
Next r
Next t

myTmpDs = myDs.GetChanges()
myDs.Merge(myTmpDs)

myDs.WriteXml("c:\Parsley.xml", xmlWriteMode.WriteSchema)

The getchanges call returns the non deleted rows, the
merge call adds these rows to the main dataset. I have
read elsewhere that I need a primary key? There is one on
the SQL table the xml is extracted from but nothing in the
xml to indicate this.

Ta v'ry much
Parsley
 
Hi Parsely,

You might call myDs.AcceptChanges after load.
 
Hey thanks Miha

When I do this after loading the xml it works, this is
great but I fail to understand why it works?! Could you
possible shed light on this for me.

Thanks once again
Parsley

-----Original Message-----
Hi Parsely,

You might call myDs.AcceptChanges after load.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Hi All

I'm experiencing the problem of dataset.getchanges
returning unmodified rows only :

myDs.ReadXml("c:\Parsley.xml", xmlReadMode.Auto)
For Each t In myDs.Tables
For Each r In t.Rows
If r.Item("Deleted").ToString = "True" Then
r.Delete()
Exit For
End If
Next r
Next t

myTmpDs = myDs.GetChanges()
myDs.Merge(myTmpDs)

myDs.WriteXml("c:\Parsley.xml", xmlWriteMode.WriteSchema)

The getchanges call returns the non deleted rows, the
merge call adds these rows to the main dataset. I have
read elsewhere that I need a primary key? There is one on
the SQL table the xml is extracted from but nothing in the
xml to indicate this.

Ta v'ry much
Parsley


.
 
Hi,

That's because ReadXml actually inserts rows (the same does Fill method)
into table thus their status is RowStatus.Added.
It simply doesn't call AcceptChanges (which Fill does) at the end - so all
rows remain marked as Added.
That's why GetChanges picks them (it picks all non - Unchanged rows).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


Hey thanks Miha

When I do this after loading the xml it works, this is
great but I fail to understand why it works?! Could you
possible shed light on this for me.

Thanks once again
Parsley

-----Original Message-----
Hi Parsely,

You might call myDs.AcceptChanges after load.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Hi All

I'm experiencing the problem of dataset.getchanges
returning unmodified rows only :

myDs.ReadXml("c:\Parsley.xml", xmlReadMode.Auto)
For Each t In myDs.Tables
For Each r In t.Rows
If r.Item("Deleted").ToString = "True" Then
r.Delete()
Exit For
End If
Next r
Next t

myTmpDs = myDs.GetChanges()
myDs.Merge(myTmpDs)

myDs.WriteXml("c:\Parsley.xml", xmlWriteMode.WriteSchema)

The getchanges call returns the non deleted rows, the
merge call adds these rows to the main dataset. I have
read elsewhere that I need a primary key? There is one on
the SQL table the xml is extracted from but nothing in the
xml to indicate this.

Ta v'ry much
Parsley


.
 
Miha, Thankyou for being so helpful..
-----Original Message-----
Hi,

That's because ReadXml actually inserts rows (the same does Fill method)
into table thus their status is RowStatus.Added.
It simply doesn't call AcceptChanges (which Fill does) at the end - so all
rows remain marked as Added.
That's why GetChanges picks them (it picks all non - Unchanged rows).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


Hey thanks Miha

When I do this after loading the xml it works, this is
great but I fail to understand why it works?! Could you
possible shed light on this for me.

Thanks once again
Parsley

-----Original Message-----
Hi Parsely,

You might call myDs.AcceptChanges after load.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Parsley" <[email protected]> wrote
in
message
Hi All

I'm experiencing the problem of dataset.getchanges
returning unmodified rows only :

myDs.ReadXml("c:\Parsley.xml", xmlReadMode.Auto)
For Each t In myDs.Tables
For Each r In t.Rows
If r.Item("Deleted").ToString = "True" Then
r.Delete()
Exit For
End If
Next r
Next t

myTmpDs = myDs.GetChanges()
myDs.Merge(myTmpDs)

myDs.WriteXml("c:\Parsley.xml", xmlWriteMode.WriteSchema)

The getchanges call returns the non deleted rows, the
merge call adds these rows to the main dataset. I have
read elsewhere that I need a primary key? There is
one
on
the SQL table the xml is extracted from but nothing
in
the
xml to indicate this.

Ta v'ry much
Parsley



.


.
 
Back
Top