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.
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.
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
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);
}
Bookmarks