chandra_ags
New member
- Joined
- May 26, 2009
- Messages
- 2
- Programming Experience
- Beginner
Hi,
I'm a VB.net beginner
I have the following code that will create an xml file from a sql database
-------------------------------------------------------------------------
Imports system.data
Imports System.Data.SqlClient
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection
Dim Adpt As SqlDataAdapter
'Dim dataRow, dbRow As DataRow
Dim dsXml As New DataSet
Dim dsDBTable As New DataSet("customer")
'Dim cmdBuilder As SqlCommandBuilder
'dsXml.WriteXml("C:\Users\eBis\Documents\Visual Studio 2005\Projects\WindowsApplication5\WindowsApplication5\bin\customer2.xml")
conn = New SqlConnection("Server=localhost;database=dbname;uid=username;PASSWORD=password;")
conn.Open()
Adpt = New SqlDataAdapter("select * from customer", conn)
Adpt.Fill(dsDBTable, "customer")
Dim doc As New XmlDataDocument(dsDBTable)
doc.Save("Newcustomer.xml")
End Sub
End Class
----------------------------------------------------------------------------
the xml file that generated is something looks like this:
<customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
</customer>
--------------------------------------------------------------------------
my question are:
1. the xml generated is from all the data in that database, can I create the xml file whice only based on the data from the last row of my database? how to do that?
2. there is some formating problem,
<customer>
<customer>
---data---
</customer>
</customer>
how to fix this problem and make it become
<?xml version="1.0" standalone="no"?>
<customer>
---- data ----
</customer>
please help me...thank you...
I'm a VB.net beginner
I have the following code that will create an xml file from a sql database
-------------------------------------------------------------------------
Imports system.data
Imports System.Data.SqlClient
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection
Dim Adpt As SqlDataAdapter
'Dim dataRow, dbRow As DataRow
Dim dsXml As New DataSet
Dim dsDBTable As New DataSet("customer")
'Dim cmdBuilder As SqlCommandBuilder
'dsXml.WriteXml("C:\Users\eBis\Documents\Visual Studio 2005\Projects\WindowsApplication5\WindowsApplication5\bin\customer2.xml")
conn = New SqlConnection("Server=localhost;database=dbname;uid=username;PASSWORD=password;")
conn.Open()
Adpt = New SqlDataAdapter("select * from customer", conn)
Adpt.Fill(dsDBTable, "customer")
Dim doc As New XmlDataDocument(dsDBTable)
doc.Save("Newcustomer.xml")
End Sub
End Class
----------------------------------------------------------------------------
the xml file that generated is something looks like this:
<customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
<customer>
<Service>Balance</Service>
<Folio>1000</Folio>
<MerchantID>1234</MerchantID>
<password>
</password>
<Workstation>3</Workstation>
<InvoiceNumber>110738</InvoiceNumber>
<Waiter>1</Waiter>
</customer>
</customer>
--------------------------------------------------------------------------
my question are:
1. the xml generated is from all the data in that database, can I create the xml file whice only based on the data from the last row of my database? how to do that?
2. there is some formating problem,
<customer>
<customer>
---data---
</customer>
</customer>
how to fix this problem and make it become
<?xml version="1.0" standalone="no"?>
<customer>
---- data ----
</customer>
please help me...thank you...