Introduction
Hi,
There is always been a need that there will be an intelligent middle Layer between Database Server and the UI Code. There are many ways but one fantastic approach came in picture with the XML. There are rich classes in System.XML which make it pretty simple and effective. Here i had made a similar application where I am solving two purpose. One thing is still the things has not come as Code Behind Approach in case of Mobile Forms and whatever till now we had done is not recognized under that approach.
And secondly using XML as a middle tier to DataBase Server and UI Code.
Check out this Application
Source Code
This Piece of code will generate the XML File and saved it in the given location and return the location in the form of String.
//WriteXML.cs
using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.IO;
using System.Text;
namespace WriteXML
{
public class WriteXML
{
public string genXMl()
{
String s="E:/ASPXSITE/DATAXML/myXmlData.xml";
SqlConnection myConn = new SqlConnection
("server=localhost;uid=sa;pwd=;database=Shivani");
String mySql = "SELECT top 10 Name,Id from User_Detail";
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(mySql,myConn);
// Build the DataSet
DataSet myDs = new DataSet();
adapter.Fill(myDs, "User_Detail");
// Get a FileStream object
FileStream myFs = new FileStream(s,FileMode.OpenOrCreate,FileAccess.Write);
// Apply the WriteXml method to write an XML document
myDs.WriteXml(myFs);
myFs.Close();
return s;
}
}
compile this as
csc /r:System.dll,System.Data.dll,System.Xml.dll /target:library /out:GenXML.dll WriteXML.cs
//and save it in directory bin in u r server
Now here is our Code which will call this Class
Join the conversation! Your thoughts help the community grow.