PC Review


Reply
Thread Tools Rate Thread

Creating a DataSet with Data and Schema based on data in DataRow

 
 
Andy Sjostrom
Guest
Posts: n/a
 
      24th Feb 2004
Hi!
I have a DataSet (dsTracking) which contains a row is updated with DataSet
XML and inline Schema.
So, in a DataRow I have XML data and schema that can be used to create a
DataSet.
The XML data and schema was created using DataSet.WriteXml with the
appropriate XmlWriteMode:


ds.WriteXml(xtw, XmlWriteMode.WriteSchema);

How can I create a DataSet based on data in a DataRow?

Using DataSet.ReadXml () I can specify XmlReadMode.ReadSchema as the second
argument. But what about the first?


I have tried this:

DataSet ds = new DataSet();
MemoryStream ms = new MemoryStream();

StreamWriter sw = new StreamWriter(ms);

sw.Write(dsTracking.Tables["TrackingDataTable"].Rows[0]["DataSetXML"]);

ms.Seek(0, SeekOrigin.Begin);

StreamReader sr = new StreamReader(ms);

ds.ReadXml(sr.ReadToEnd(), XmlReadMode.ReadSchema);


The above code throws an exception at the ds.ReadXml... The exception is:
"Additional information: Invalid URI: The URI scheme is not valid."

Thanks,

Andy Sjostrom
MS MVP - Mobile Devices


 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      24th Feb 2004
Hi Andy,

I this sample something your are looking for?

\\\
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("test");
dt.Columns.Add(dc);
ds.Tables.Add(dt);
MemoryStream ms = new MemoryStream();
ds.WriteXml(ms,XmlWriteMode.WriteSchema);
ms.Position=0;
DataSet ds2 = new DataSet();
ds2.ReadXml(ms,XmlReadMode.ReadSchema);
ds2.WriteXml(@"C:\test1.xml",XmlWriteMode.WriteSchema);
///

I hope this helps?

Cor


 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      24th Feb 2004
Hi Andy,

I did make that dataset as a sample to do your problem, but I have another
sample, I still have.

The only problem for you is that it goes for you in the wrong direction, but
I think it cannot be that hard to change that in the right direction :-)

It is also VB.net (But the changes are not that difficult to do in my
opinion to C#)

If you do nto succeed tell than I will look to it tomorrow.

Cor

Dim ds As New DataSet
Dim dt As New DataTable("parameters")
For c As Integer = 1 To 10
Dim dc As New DataColumn("elem" & c.tostring)
dt.Columns.Add(dc)
Next
For r As Integer = 1 To 10
Dim dr As DataRow = dt.NewRow
For c As Integer = 1 To 10
dr("elem" & c.tostring) = _
r.ToString & c.tostring ' or just dr(c) but to show you
Next
dt.Rows.Add(dr) ' can also before but I find this looking nicer
Next
ds.Tables.Add(dt)
-------------------------end of building of the testset

Dim ser As XmlSerializer = New XmlSerializer(GetType(DataSet))
Dim ms As New IO.MemoryStream
Dim sw As IO.TextWriter = New IO.StreamWriter(ms)
ser.Serialize(sw, ds)
Dim b As Long = ms.Length
ms.Position = 0
Dim sr As IO.TextReader = New IO.StreamReader(ms)
Dim xmlstring As String = sr.ReadToEnd
sw.Close()
sr.Close()
ms.Close()


 
Reply With Quote
 
Andy Sjostrom
Guest
Posts: n/a
 
      24th Feb 2004
Thanks, Cor!
I have code that goes in "the wrong direction". VB.NET is not an issue but I
wonder if the System.Text.Encoding might be...

Best regards,

-Andy.



"Cor" <(E-Mail Removed)> wrote in message
news:#LlR1gw#(E-Mail Removed)...
> Hi Andy,
>
> I did make that dataset as a sample to do your problem, but I have another
> sample, I still have.
>
> The only problem for you is that it goes for you in the wrong direction,

but
> I think it cannot be that hard to change that in the right direction :-)
>
> It is also VB.net (But the changes are not that difficult to do in my
> opinion to C#)
>
> If you do nto succeed tell than I will look to it tomorrow.
>
> Cor
>
> Dim ds As New DataSet
> Dim dt As New DataTable("parameters")
> For c As Integer = 1 To 10
> Dim dc As New DataColumn("elem" & c.tostring)
> dt.Columns.Add(dc)
> Next
> For r As Integer = 1 To 10
> Dim dr As DataRow = dt.NewRow
> For c As Integer = 1 To 10
> dr("elem" & c.tostring) = _
> r.ToString & c.tostring ' or just dr(c) but to show you
> Next
> dt.Rows.Add(dr) ' can also before but I find this looking

nicer
> Next
> ds.Tables.Add(dt)
> -------------------------end of building of the testset
>
> Dim ser As XmlSerializer = New XmlSerializer(GetType(DataSet))
> Dim ms As New IO.MemoryStream
> Dim sw As IO.TextWriter = New IO.StreamWriter(ms)
> ser.Serialize(sw, ds)
> Dim b As Long = ms.Length
> ms.Position = 0
> Dim sr As IO.TextReader = New IO.StreamReader(ms)
> Dim xmlstring As String = sr.ReadToEnd
> sw.Close()
> sr.Close()
> ms.Close()
>
>



 
Reply With Quote
 
Andy Sjostrom
Guest
Posts: n/a
 
      24th Feb 2004
Currently investigating:

ds.ReadXml( new
StringReader(dsTracking.Tables["TrackingDataTable"].Rows[0]["DataSetXML"].To
String()), XmlReadMode.ReadSchema );



which looks promising. Will report back if this solves my problem!



Andy Sjostrom

MS MVP - Mobile Devices


 
Reply With Quote
 
Andy Sjostrom
Guest
Posts: n/a
 
      24th Feb 2004
It works!
Full source code to appear on a web site near you soon!

Andy Sjostrom
MS MVP - Mobile Devices


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to populate a DataSet schema with data from and XML string? =?Utf-8?B?U2hhcm9u?= Microsoft C# .NET 3 5th Sep 2005 02:10 AM
Re: Binary Data Type in DataSet Xml Schema jji Microsoft ADO .NET 0 16th Nov 2004 09:39 PM
How to generate dataSet XML schema by draggin & dropping data elements using VS. feng Microsoft VB .NET 0 7th Jun 2004 10:30 PM
Mapping a flat data table to a typed DataSet with complex schema Stephen Walch Microsoft ADO .NET 11 1st Dec 2003 02:03 PM
Trouble retrieving data from a dataset to a datarow. Dirk Vervecken Microsoft C# .NET 1 29th Oct 2003 02:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:37 PM.