Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-12-2008
Member
 
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.
Reply With Quote
  #2  
Old 29-12-2008
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #3  
Old 29-12-2008
Member
 
Join Date: May 2008
Posts: 2,383
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);

}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Creating xml File from database table in VB.Net"
Thread Thread Starter Forum Replies Last Post
Creating a Hash Table in java Sheenas Software Development 5 19-02-2010 07:24 PM
Defining primary key on database table Garlands Software Development 4 09-02-2010 09:09 PM
Creating Database link in database Lachlann Software Development 3 28-01-2010 01:17 PM
Creating new table from existing table KALANI84 Software Development 3 29-10-2009 09:35 PM
Check if database or table exists Xan Software Development 2 29-05-2009 04:53 PM


All times are GMT +5.5. The time now is 07:15 PM.