Can we populate a XML formated string into a dataset?

G

Guest

When I check the syntax of dataset, It seems that dataset can only read data
from file. (e.g., datset.read(string filename), dataset.readxml(string
filename)).

If I have a string with XML format that is transfered from somewhere else,
how can I read the string and populate it into a dataset, then display the
data in a data grid?

Thanks for any help.

David
 
G

Guest

I have searched Yahoo and Microsoft web, some info seems useful but doesn't
work.

I will try to find some.

David
 
J

Juan T. Llibre

Here's a quick example :

<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load(sender as Object, e as EventArgs)
Dim myDataSet as New DataSet()

myDataSet.ReadXml(Server.MapPath("some.xml"))

dgSome.DataSource = myDataSet
dgSome.DataBind()
end sub
</script>

<body>
<asp:datagrid id="dgSome" runat="server" />
</body>

If you are getting the XML from a stream,
you'll need to write it to disk before using this method.

That shouldn't present too many complications.
 
G

Guest

Incase you have yr xml in the form of a string and not a physical .xml file
on the server, in that case you could try this option.

Load the string into an StringReader object and the same can be passed to
the ReadXml method of the dataset.

StringReader strReader = new StringReader(str);
DataSet _ds = new DataSet();
_ds.ReadXml(strReader);
Response.Write(_ds.GetXml());

This should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top