.net WriteXmlSchema ReadXmlSchema Stream Root Element Missing

So today i decided i needed to clone the schema of a dataset and then put it in an empty dataset. Once this was done i could selectively move rows to the new dataset.

The first thing i did was to read the data into an empty memorystream object.

Dim tempstream As New IO.MemoryStream
skeyobj.AssessmentDataset.WriteXmlSchema(tempstream)

Next i would put read that into the new dataset

newskey.AssessmentDataset.ReadXmlSchema(tempstream)

Now common since would make me think this would work and i would just be moving on, but………. This was not the case. I got an error “Root Element is missing”?

How? I just copied it from one dataset to the other. Well upon further inspection you realize the position of the pointer in the memorystream is still at the end of the file, so when you pass it to the readxmlschema function it starts the read from that point at the end and not the beginning.

Solution? Well that was simple. Just set the streams pointer position back to 0 and you are good to go.

tempstream.Position = 0

So in the end this is what it should look like together.

skeyobj.AssessmentDataset.WriteXmlSchema(tempstream)
tempstream.Position = 0
newskey.AssessmentDataset.ReadXmlSchema(tempstream)

I would have figured the read would move the position back itself, but we all know what happens when we make assumptions……EXCEPTIONS!!!!!!!!!!!!

 

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

6 Responses to .net WriteXmlSchema ReadXmlSchema Stream Root Element Missing

  1. ReadyMakers.com says:

    Wow, fantastic weblog format! How lengthy have you been running a blog for? you made blogging look easy. The total glance of your website is fantastic, as neatly as the content!

  2. Readymakers LTD says:

    Thanks a lot for sharing this with all folks you really recognize what you’re speaking about! Bookmarked. Kindly also visit my site =). We may have a hyperlink alternate agreement between us

  3. Readymakers.de says:

    It’s actually a nice and useful piece of information. I am happy that you simply shared this useful information with us. Please stay us informed like this. Thank you for sharing.

  4. My Homepage says:

    Spot on with this write-up, I truly believe this site needs significantly a lot more consideration. I’ll probably be once more to read significantly a lot more, thanks for that information. 642884

  5. Ι ԁon’t even know how I ended up here, but I thought this post was good. I don’t know who yοu arе but definitely you’re going to a famous blogger if you are not already 😉 Cheers!

    Have a look at my web-site :: automation Software

  6. Celsa says:

    WОW just what Ι wаs seaгchіng for.
    Came hеre by searching for Знакомства
    Камышин

    Fееl fгeе tо visit my ωebpage .
    .. Знакомства Люберцы (Celsa)

Leave a Reply to Readymakers LTD Cancel reply

Your email address will not be published. Required fields are marked *