Solved

Create XML String from DataView?

Posted on 2007-04-02
4
738 Views
Last Modified: 2013-11-07
Using VWD 2005 and SQL 2005

What started out to be a quick and dirty tool has proved to be quite a distraction for me.  I have a need to retrieve records from a stored procedure, serialize them into XML and run a transformation on them with an XSL.

My first thought was to create a DAL.  So, using the dataset wizard I made a data object with one method to retrieve records with a parameter.

Next I dropped an XML object onto my web form.  I set the TransformationSource property to my XSL stylesheet and my thought was to set the DocumentContent property to an XML string.

Where was the XML content to come from?  I knew that the dataset has the GetXML method.  However, the DAL tableadapters return a datatable.  I can make a dataview from that, but that doesn't really help either.

I know that I can just code this by hand in a few minutes and get the XML from a dataset, but like I said - this really got me distracted - and I was wondering if there was a way to serialize the contents of the datatable or dataview that is returned.
0
Comment
Question by:manicsquirrel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:jef06
ID: 18841615
Try this :)

DataView data = new DataSet().Tables[0].DefaultView;
XmlSerializer serializer = new XmlSerializer(data.GetType());
                StringBuilder sb = new StringBuilder();
                TextWriter writer = new StringWriter(sb);

                serializer.Serialize(writer, data);
                StringReader reader = new StringReader(writer.ToString());

                DataSet dst = new DataSet();
                dst.ReadXml(reader);
                dv = new DataView(dst.Tables[0]);
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 18842706
Serialize
\\\\
 Dim sw As New System.IO.StringWriter
 ds.WriteXml(sw)
 Dim mystring As String = sw.tostring
///
Deserialize
\\\
 Dim sr As New System.IO.StringReader(mystring)
 Dim ds2 As New DataSet
 ds2.ReadXml(sr)
///
0
 
LVL 6

Author Comment

by:manicsquirrel
ID: 18844222
I like using my brain a little, and while iboutchkine didn't write the routing for me, it was just enough to make a light bulb go off.  My resulting solution was (remember, I already have a dataview - dv)

        Dim sw As New System.IO.StringWriter
        dv.Table.WriteXml(sw)
        Dim str As String = sw.ToString

Now I have effectively retrieved serialized data from my dataview which is what I was wanting.  Thanks for both of your responses.
0
 
LVL 6

Author Comment

by:manicsquirrel
ID: 18844231
Did I type "routing"?  I meant "routine".
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create a button class for use in all vb.net apps 5 42
SSIS Column mapping 5 40
Make borderless form movable by user 2 25
ASP.NET VB code for check and insert in a table 4 42
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question