Strongly-Typed DataSet Woes

S

Scott M.

In ADO.NET 2.0, using VS 2005 Pro., I have visually made a strongly-typed
dataset by dragging a SQL Server 2005 table from my Server Explorer window
(where I've previously made a connection) onto a blank DataSet designer.

This works just fine, and a TableAdapter is generated as well. In code, I
can use the TableAdapter's Fill method to populate a new instance of my
dataset with no problems.

But, if I try to pass the xml representation of the dataset (using the
dataset.GetXML() method), the dataset's namespace is rendered as:

xmlns=\"http://blah/blah\">

This is causing me to NOT be able to read this XML into a different dataset
later. I've tried simply replacing the escape code with nothing or even
" to no avial, nothing modifies it.

Why is this doing this and how can I change it?

-Scott
 
W

Wen Yuan Wang [MSFT]

Hello Scott,

\" is an escape char in C#. It couldn't block you from passing it into
Dataset.
Could you please let me know how did you pass the xml representation into
another dataset?
Did you get any error message?

I tried the following code on my side. It works fine. Would you please try
it and let me know the result?

DataSet1TableAdapters.Table_1TableAdapter tt = new
WindowsApplication56.DataSet1TableAdapters.Table_1TableAdapter();
DataSet1 ds=new DataSet1();
tt.Fill(ds.Table_1);
string s = ds.GetXml();

Byte[] xmlbyte=System.Text.Encoding.Default.GetBytes(s);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(xmlbyte, 0, xmlbyte.Length);
ms.Position = 0;

System.Xml.XmlReader xr = System.Xml.XmlReader.Create(ms);
DataSet1 ds2 = new DataSet1();
ds2.ReadXml(xr);


Hope this helps. Let me know if you face any further issue. We are glad to
assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Scott M.

I'm using a strongly-typed DataSet and its accompanying TableAdapter's Fill
method to get data from my SQL Server database and that part is working just
fine.

I'm then using this dataset's GetXML method and passing that result via web
service to a UI layer where an exact duplicate of the strongly typed dataset
also exists.

As I prepare to put the web serivices's xml into a new, but empty
strongly-typed dataset, I am first using a StringReader to first receive the
XML string and then I am using the dataset's ReadXML method and passing it
my StringReader.

The error is encountered when the DataSet attempts to load the StringReader
via ReadXML. I have confirmed what the string is at this time and it does
contain the \" escape sequence around the root element's xmlns value.

Despite your statement that this couldn't block me from reading the string
into the DataSet, I have confirmed that this is the problem. With these
escape sequences in place, the string is not well-formed xml and will not
load into the DataSet, without them (and just regular quotes), the string
does load without issue.

I will try using an XMLReader as you show below, but have always used
StringReaders in the past without incident.

-Scott
 
S

Scott M.

I've got it working now. I was inadvertently using a StreamReader to read
the XML string in, rather than a StringReader. That's what I get for coding
at 3am!

Thanks.


Scott M. said:
I'm using a strongly-typed DataSet and its accompanying TableAdapter's
Fill method to get data from my SQL Server database and that part is
working just fine.

I'm then using this dataset's GetXML method and passing that result via
web service to a UI layer where an exact duplicate of the strongly typed
dataset also exists.

As I prepare to put the web serivices's xml into a new, but empty
strongly-typed dataset, I am first using a StringReader to first receive
the XML string and then I am using the dataset's ReadXML method and
passing it my StringReader.

The error is encountered when the DataSet attempts to load the
StringReader via ReadXML. I have confirmed what the string is at this
time and it does contain the \" escape sequence around the root element's
xmlns value.

Despite your statement that this couldn't block me from reading the string
into the DataSet, I have confirmed that this is the problem. With these
escape sequences in place, the string is not well-formed xml and will not
load into the DataSet, without them (and just regular quotes), the string
does load without issue.

I will try using an XMLReader as you show below, but have always used
StringReaders in the past without incident.

-Scott

Wen Yuan Wang said:
Hello Scott,

\" is an escape char in C#. It couldn't block you from passing it into
Dataset.
Could you please let me know how did you pass the xml representation into
another dataset?
Did you get any error message?

I tried the following code on my side. It works fine. Would you please
try it and let me know the result?

DataSet1TableAdapters.Table_1TableAdapter tt = new
WindowsApplication56.DataSet1TableAdapters.Table_1TableAdapter();
DataSet1 ds=new DataSet1();
tt.Fill(ds.Table_1);
string s = ds.GetXml();

Byte[] xmlbyte=System.Text.Encoding.Default.GetBytes(s);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(xmlbyte, 0, xmlbyte.Length);
ms.Position = 0;

System.Xml.XmlReader xr = System.Xml.XmlReader.Create(ms);
DataSet1 ds2 = new DataSet1();
ds2.ReadXml(xr);


Hope this helps. Let me know if you face any further issue. We are glad
to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
W

Wen Yuan Wang [MSFT]

Hello Scott,

That's great. It seems you made a small mistake when coding in midnight.
But this accident resolved your issue...
StreamReader is a good way. I have also tried with "StringReader' on my
side just now. The code is as below:

DataSet1TableAdapters.Table_1TableAdapter tt1 = new
ConsoleApplication1.DataSet1TableAdapters.Table_1TableAdapter();
DataSet1 ds = new DataSet1();
tt1.Fill(ds.Table_1);
string s = ds.GetXml();

System.IO.StringReader sr = new StringReader(s);

DataSet1 ds2 = new DataSet1();
ds2.ReadXml(sr);

But, on my side, it works fine. I didn't get any error message. I'm not
sure if you still have time to drill into this issue.
If true, would you please send me your simple project? I will tried it on
my side and perform further research. We are glad to assist you.
My email address is (e-mail address removed)

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top