473,378 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to Load an Xml C# String into a DataSet

I have a string containing the XML text of my database. How can I create a
data set from this String?

The simple way would be to convert the String to a memory stream and then
read that memory stream using DataSet.ReadXml(...). However I can't find a
way to create a MemoryStream from a String. One of the constructors for
MemoryStream needs a byte[] array. I don't know how to get this out of the
string. I can get a char[] array but that's not compatible with a byte[]
array.

This is the sample code I was trying to use:

String sClassesXml = (String) Session["ClassesXml"];
// doesn't work!!!
byte[] baClassesXml = sClassesXml.ToCharArray();
MemoryStream ms = new MemoryStream(baClassesXml);
DataSet ds = new DataSet();
ds.ReadXml(ms);
It would be easy in C++!

Ed
--
Edward E.L. Mitchell
Web: www.racesail.org
Phone: (239)415-7039
6707 Daniel Court
Fort Myers, FL 33908
Jul 21 '05 #1
2 31816
Edward,

To serialize/deserialize a dataset you don't need directly a memorystream,
maybe you can try this one.
In this message changed from VBNet to C# so watch typos

Serialize
\\\\
System.IO.StringWriter sw = New System.IO.StringWriter();
ds.WriteXml(sw);
string mystring = sw.tostring();
///
Deserialize
\\\
System.IO.StringReader sr = new System.IO.StringReader(mystring);
DataSet ds2 = new DataSet();
ds2.ReadXml(sr);
///
I hope this helps a little bit?

Cor
Jul 21 '05 #2
Cor,

That worked like a charm. I hadn't noticed the overload for Read/WriteXml
that took a TextWriter object. I was focused on the stream argument since I
know how to change a string to a stream in C++!.

Ed

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O$****************@tk2msftngp13.phx.gbl...
Edward,

To serialize/deserialize a dataset you don't need directly a memorystream,
maybe you can try this one.
In this message changed from VBNet to C# so watch typos

Serialize
\\\\
System.IO.StringWriter sw = New System.IO.StringWriter();
ds.WriteXml(sw);
string mystring = sw.tostring();
///
Deserialize
\\\
System.IO.StringReader sr = new System.IO.StringReader(mystring);
DataSet ds2 = new DataSet();
ds2.ReadXml(sr);
///
I hope this helps a little bit?

Cor

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stanley J Mroczek | last post by:
i got this far Sub getvin(ByVal sender As Object, ByVal e As System.EventArgs) Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex) If (Not item Is Nothing) Then Dim txtVin As...
1
by: Tom G | last post by:
The following is a small sample of my XML Data. When I load it to a dataset it only loads the 'Zone' elements and ignores loading the 'Field' elements. <zone id="1234" name="EMPLOYMENT_INFO">...
0
by: Patrick Kearney | last post by:
Hi All, I have seen this type of question raised in various groups but no one has supplied a definitive answer. I am trying to load a dataset schema that has an xs:include. Project policy is to...
4
by: jaime | last post by:
1 I load a text file into a dataset, after doing a bit of work.. 2 Now I have a dataset full of data that I like to transfer to a data base 3 My problem is that if the rowstate of the row is set to...
1
by: Anandan | last post by:
Hi, This is regarding Dataset Filter: WILDCARD CHARACTERS Both the * and % can be used interchangeably for wildcards in a LIKE comparison. If the string in a LIKE clause contains a * or %,...
1
by: Newbee | last post by:
How do I load a data set with an XML string.(not Xml file).
3
by: David P. Donahue | last post by:
I'm re-writing an application in C# that was originally written in Delphi 7. The heart of the application is a DataSet displayed in a DataGrid. One of the main functions of the previous...
4
by: adwooley2 | last post by:
Can't seem to find anything that works for me. I have a small bit of HTML that is stored in a string variable. I want to assign this string to an mshtml object (IHTMLDocument2 I believe), so that...
2
by: SmartbizAustralia | last post by:
Hi, This seems to be a neglected bit of info as everyone gets carried away with data binding examples instead. Can simply use the datareader as below: Private Sub PopulateControls1() Dim...
2
by: TS | last post by:
for some reason i have code in a projcect that uses this method and it works. i have almost the exact same project/files (i just renamed some stuff) in another directory. the code works in the 1st...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.