Results 1 to 3 of 3

Thread: Creating xml File from database table in VB.Net

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Creating xml File from database table in VB.Net

    Hi,

    I am developing a new project in vb.net,
    and for that i want to create a xml file from a database table but,
    i am not getting a code for that.
    Please help me for these.

    Thanks.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Creating xml File from database table in VB.Net

    HI,
    check this code its may help u

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Xml

    Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim strConn As String
    'create connection to database table.
    strConn = "USER=asdfasdf;PASSWORD=asdf;SERVER=asdf;DATABASE=Emp"
    Dim MySQL As String = "Select empno, empname from kk"
    Dim MyConn As New SqlClient.SqlConnection(strConn)
    Dim ds As DataSet = New DataSet()
    Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
    'Fill the Table values to Dataset
    Cmd.Fill(ds, "Emptbl")
    'Bind the dataset values to xmldatadocument
    Dim doc As New XmlDataDocument(ds)
    doc.Save(MapPath("NewXMLName.xml"))
    'This is where we are saving the data in an XML file NewXMLName.xml
    End Sub
    End Class

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Creating xml File from database table in VB.Net

    Use the following code:

    using(SqlConnection connObj= new SqlConnection(connectionstring))
    {
    DataSet ds = new DataSet("DSName");

    connObj.Open()

    SqlCommand sqlCmd = new sqlCommand(connObj,"Select * from tblName");

    ds.Load(sqlCmd.ExecuteReader,LoadOption.OverwriteChanges,"tblName");

    ds.WriteXml(strXmlfileName);

    }

Similar Threads

  1. Creating a Hash Table in java
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 07:24 PM
  2. Defining primary key on database table
    By Garlands in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 09:09 PM
  3. Creating Database link in database
    By Lachlann in forum Software Development
    Replies: 3
    Last Post: 28-01-2010, 01:17 PM
  4. Creating new table from existing table
    By KALANI84 in forum Software Development
    Replies: 3
    Last Post: 29-10-2009, 09:35 PM
  5. Check if database or table exists
    By Xan in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,219,483.97390 seconds with 17 queries