Home > XML > Convert database tables into XML and Schema

Convert database tables into XML and Schema


Hi

try this example :-

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class xml : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strConnect = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
        string strSelect = "SELECT * FROM Employees";
        DataSet objDataSet = new DataSet();
        SqlConnection objConnect = new SqlConnection(strConnect);
        SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSelect, objConnect);
        objDataAdapter.Fill(objDataSet, "Employees");
        string strVirtualPath = Request.ApplicationPath + "/Employees.xml";
        string strVSchemaPath = Request.ApplicationPath + "/Employees.xsd";
        objDataSet.WriteXml(Request.MapPath(strVirtualPath));
        objDataSet.WriteXmlSchema(Request.MapPath(strVSchemaPath));
    }
}

Hope this helps

Good Luck

Advertisements
Categories: XML
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: