Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the following query in ssms, it will show the given result but I use this query in vb.net coding it will show different result. I want the ssms result.

select unit_name, Unit_PrintName from unit_table for xml path('customer'), root('erpimportdata')


<erpimportdata>
<customer>
<unit_name>Doz > & A
<unit_printname>Doz

<customer>
<unit_name>Abc
<unit_printname>Abc

<customer>
<unit_name>Zzzzzzzz
<unit_printname>Zzzzzzzz

<customer>
<unit_name>Nos
<unit_printname>Nos




RESULT OF VB.NET CODE.
<?xml version="1.0" standalone="yes"?>
<newdataset>

<xml_f52e2b61-18a1-11d1-b105-00805f49916b><erpimportdata><customer><unit_name>Doz &gt; &amp; A</unit_name><Unit_PrintName>Doz</Unit_PrintName></customer><customer><unit_name>Abc</unit_name><Unit_PrintName>Abc</Unit_PrintName></customer><customer><unit_name>Zzzzzzzz</unit_name><Unit_PrintName>Zzzzzzzz</Unit_PrintName></customer><customer><unit_name>Nos</unit_name><Unit_PrintName>Nos</Unit_PrintName></customer></erpimportdata>



What I have tried:

Dim ldb As New kgmtools.clsDB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim sql As String
    sql = "select unit_name, Unit_PrintName from unit_table for xml path('customer'),  root('erpimportdata')"


    ldb.OpenDB("kgmmurugesh\kgmexpress", "kgmerp_abc")
    Writetoxml(ldb, sql, "d:\storesdata.xml")
    End

End Sub



Private Sub Writetoxml(ByVal pdb As kgmtools.clsDB, ByVal pstrquery As String, ByVal pstrfilename As String)
    Try

        Dim ldataset As New DataSet
        Dim ldataadapter As SqlDataAdapter


        ldataadapter = New SqlDataAdapter(pstrquery, pdb.DBConnect)
        ldataadapter.Fill(ldataset)
        ldataset.WriteXml(pstrfilename)

    Catch ex As Exception
        MsgBox(ex.Message.ToString)
    End Try
End Sub
Posted
Updated 9-Apr-18 23:07pm

1 solution

Well yes. What did you expect?
You aren't doing the same thing with both systems.
The SQL query returns the same XML in SSMS as the query in the VB code: but you treat it differently and the WriteXML has more info to output than just the "raw" XML string: it has the column name "xml_f52e2b61-18a1-11d1-b105-00805f49916b" for starters!
If you want to store the XML, then you need to handle the raw data, not just write the dataset.
 
Share this answer
 
Comments
kgmmurugesh 10-Apr-18 9:30am    
I need raw xml string. But i want it as xml file.
OriginalGriff 10-Apr-18 9:56am    
And what is stopping you from wrapping the raw XML data in an XML file header?
kgmmurugesh 11-Apr-18 2:46am    
<?xml version="1.0" standalone="yes"?>
<newdataset>

<xml_f52e2b61-18a1-11d1-b105-00805f49916b><erpimportdata><row unit_name="Nos" Unit_PrintName="Nos"/></erpimportdata>




It will translate tag to <. So I cannot read the file.
kgmmurugesh 11-Apr-18 2:48am    
I want erpimportdata as new element.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900