.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> XML >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Generating XML files and Write the Deatils from DataBase in XML file

Posted By:Prasanti Prusty       Posted Date: January 25, 2010    Points: 10    Category: XML    URL: http://www.dotnetspark.com  

This code sample will generate Nodes and Child nodes based on the DataBase Column Names and write in the XML file using vb.net
 

 
-  
-  
1 
App. Panda 
O 
D 
18 
12500.00 
true 
 
-  
2 
Ramakrishna 
K 
R 
18 
12500.00 
false 
 
 


Codes :


Imports System.Data
Imports System.Data.SqlClient

Partial Class Default3
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Generating XML files and Write the Deatils from DataBase in XML file
        Dim strCon As String = "Password=wizardpass;Persist Security Info=True;User ID=wizard;Initial Catalog=Testing;Data Source=IBM\SQL2005" '"Server=127.0.0.1;uid=sa;pwd=;Database=Northwind;"
        Dim strSQL As String = "Select Id,Name,MiddleName,LastName,ManagerId,Salary,Status from Employee order by Id desc"
        Dim objDataSet As New DataSet()
        Dim objCon As SQLConnection
        Dim objAdapter As SQLDataAdapter

        objCon = New SQLConnection(strCon)
        objAdapter = New SQLDataAdapter(strSQL, objCon)

        objAdapter.Fill(objDataSet, "Empls")

        objDataSet.WriteXml(Server.MapPath("employee_xml_file.xml"))
        Response.Write("Check your XML file")
    End Sub
End Class

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend