Help: create dataset with xml string

M

Marco Care'

I'm developing a PPC application in VB.NET.
As it start, the PPC App make a soket connection with a PC Server, from
wich the PPC receive a string containing an XML dataset.
The PC Server APP sent the string in the folowing routine:

Dim cSql As String = Mid(data, 11, 20)
Dim CN As New System.Data.SqlClient.SqlConnection(strConn)
Dim strSQL As String = "select cod, des from Articles"
Dim scmd As New System.Data.SqlClient.SqlCommand(strSQL, CN)
Dim da = New System.Data.SqlClient.SqlDataAdapter(scmd)
Dim ds As New DataSet
da.Fill(ds, "Articles")
strSQL = "select datemov, caumov from moviments scmd = New
System.Data.SqlClient.SqlCommand(strSQL, CN)
da = New System.Data.SqlClient.SqlDataAdapter(scmd)
da.Fill(ds, "Moviments")
strSQL = "select id, title from Books"
scmd = New System.Data.SqlClient.SqlCommand(strSQL, CN)
da = New System.Data.SqlClient.SqlDataAdapter(scmd)
da.Fill(ds, "Books")
cSql = ds.GetXml
sender.Send(cSql)

....
now, the PPC receive the xml string but
I'm not able to create the local dataset from this string

can someone help me ?
thanks
 
M

Marco Care'

The PPC routine that create the dataset: the cDataSet variable contain
the xml schema captured by the soket port of the PPC. The program is in
VB for Pocket PC (compact framework)

Private Sub CreateDS()
Dim sw As System.IO.StreamWriter
sw = System.IO.File.CreateText("db.xml")
sw.Write(cDataSet)
sw.Flush()
sw.Close()

Try
ds.ReadXmlSchema("db.xml")
ds.ReadXml("db.xml")
Catch ex As Exception
MsgBox(ex.Message)
End Try
System.IO.File.Delete("db.xml")
End Sub

I would not use d phisical file to create dataset.
Can I create the dataset directly from the string as in a the PC
environment ?
Tanks.
marco care'
 
R

Ronnie Yates [MS]

You can call ReadXml(XmlReader, XmlReadMode). Create the XmlReader with a
StringReader that wraps around the xml string and pass in XmlReadMode.Auto.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Ronnie Yates [MS]

XmlReader should be XmlTextReader...
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Marco Care'

Sorry for delay.
I have read your solution but it seem that, for the PPC, application
there is not this possibility.
Perhaps I haven't understand your suggestion.
Can you write me the alternative routine I posted with your solution ?
Thanks
Follows the original sub
Private Sub CreateDS()
Dim sw As System.IO.StreamWriter
sw = System.IO.File.CreateText("db.xml")
sw.Write(cDataSet)
sw.Flush()
sw.Close()

Try
ds.ReadXmlSchema("db.xml")
ds.ReadXml("db.xml")
Catch ex As Exception
MsgBox(ex.Message)
End Try
System.IO.File.Delete("db.xml")
End Sub
 
M

Mark Ihimoyan [MSFT]

Private Sub CreateDS()
Dim sw As System.IO.StreamWriter
sw = System.IO.File.CreateText("db.xml")
sw.Write(cDataSet)
sw.Flush()
sw.Close()

Try
// This is CSharp... you'll have to translate it into VB
XmlTextReader xtr = new XmlTextReader(new
StreamReader("db.xml"));
ds.ReadXmlSchema(xtr);
ds.ReadXml(xtr);

Catch ex As Exception
MsgBox(ex.Message)
End Try
System.IO.File.Delete("db.xml")
End Sub
 
M

Marco Care'

I apologize,
probably I have not explained in correct manner my problem.
I receive, via-socket (from a PC wireless connected) a string variable,
called cDataSet.
To populate the PocketPc DataSet ds, I have to save the cDataSet string
in a physical file called db.xml. So I have to add one step to create
the dataset.
I would avoid to create the recordset from the physical file. I would
create the dataset directly from the cDataSet string.
This is possible, using the Framework, but, in a Pocket PC application,
using the Compact Framework, it doesn't seem possible.
Thanks
Marco
 
M

Mark Ihimoyan [MSFT]

When u say this is possible using the Framework, what methods do u have in
mind.
If you post a tiny sample (using the Framework) I can look at it and
suggest an efficient work around using NETCF.

Thanks.
 
M

Marco Care'

Whe I use VB.NET application and create a New Windows Application I can
use the followings lines:

private sub CreateDS(cTxt as string)
Dim ds as new DataSet
Dim xmlSR As System.IO.StringReader = New
System.IO.StringReader(cTxt)
ds.ReadXml(xmlSR, XmlReadMode.Auto)
end sub

in this case I have create a DataSet DA directly from the cTxt variable.

If I create a new VB.NET project using the SmartDeviceApplication
template and selecting the Pocket PC target the set of commands are not
the same and I cannot create a dataset directly from a string variable.
I have to save the variable to a file and then, create the dataset from
this file as in the sample I have setn you.
Particulary, the error appair in the instruction:
ds.ReadXml(xmlSR, XmlReadMode.Auto)
because the first parameter, the reader cannot be a StringReader.
Thanks
Marco
 
M

Marco Care'

Hi,
I haven't received your news from the my last post.
Isn't there hope, for me, to solve my problem ?
Best regards.
Marco
 
M

Mark Ihimoyan [MSFT]

this overload is not currently supported on v1 of NETCF.
ReadXml(TextReader reader,XmlReadMode mode) as such you would not be able
to call this method
ds.ReadXml(xmlSR, XmlReadMode.Auto)

However a possible work around as mentioned in an earlier post is to create
an XmlTextReader over your string and pass this as an argument to the
ReadXml method.

private sub CreateDS(cTxt as string)
Dim ds as new DataSet
Dim xmlSR As System.IO.StringReader = New
System.IO.StringReader(cTxt)
' create an Xmlreader over your string reader and pass it as an
argument to the ReadXml method
Dim xmlSR2 As System.Xml.XmlTextReader = new
System.Xml.XmlTextReader(xmlSR)
ds.ReadXml(xmlSR2, XmlReadMode.Auto)
end sub
 

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