PC Review


Reply
Thread Tools Rate Thread

BUG? DataSet.ReadXML with MemoryStream

 
 
Chuck Haeberle
Guest
Posts: n/a
 
      19th Jul 2003
We're using the Microsoft Application Blocks SQL Helper in our projects,
which is a great time saver but doesn't support use of Strongly Typed
DataSets.

I'm trying to find an easy way to take a generic dataset which has been
populated and transfer its data into my strongly typed data set.

Assume an XSD called FileList. I use a derived class based on the XSD since
changing the XSD regenerates its base code...

public class FileListHelper : FileList
{
....
public void SetData(DataSet data)
{
MemoryStream ms = new MemoryStream();
data.WriteXml(ms);
this.ReadXml(ms);
}
}

Now reading the overloads for ReadXML this should work, but instead I get an
error that the Root Node doesnt' exist on the ReadXML.

Any advice? Or alternate approches for taking a DataSet and moving its data
into an XSD or XSD Derivative?


 
Reply With Quote
 
 
 
 
David Keenan
Guest
Posts: n/a
 
      20th Jul 2003
Chuck,

After you do the WriteXml to the Stream your stream will
be positioned at its end.

You have to move the Memory stream back to the beginning
by setting its Position property before you can write it
out. Try changing you code to the following.

public class FileListHelper : FileList
{
.....
public void SetData(DataSet data)
{
MemoryStream ms = new MemoryStream();
data.WriteXml(ms);
// Move the stream back to the beginning
ms.Position = 0;
this.ReadXml(ms);
}
.....
}

Took me hours of tearing my hair out to work out that
one. If your trying to do anything complex with Xml in a
DataSet there are quite a few problems to get around,
although when you get it working its really cool! I have
a couple of posts in this group with issues I have been
unable to resolve, if you sort any of them out be sure to
let me know. Hope this helps.

Regards,

David
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReadXml() method: standard DataSet vs. typed DataSet MikeOtown Microsoft ADO .NET 0 6th Dec 2007 05:15 PM
DataSet.ReadXml C Glenn Microsoft C# .NET 2 29th Nov 2005 01:04 PM
Re: does DataSet.ReadXml() clear current table information on DataSet CrunkByte Microsoft Dot NET Framework 0 21st May 2005 03:11 AM
dataset.readxml psb Microsoft Dot NET 0 15th Apr 2004 08:14 PM
Possible Bug in DataSet.ReadXml() Michelle Weber Microsoft ADO .NET 1 24th Dec 2003 06:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 PM.