473,386 Members | 1,738 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,386 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 31818
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.