Here we will see that how can we fetch data from database in XML format.
using System;
using System.Data.SqlClient;
using System.Xml;
namespace test
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ReadXML
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
string connectionString = "server=.;uid=test;pwd=test;database=test";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("select * from test for xml auto, elements", con);
con.Open();
XmlReader reader = cmd.ExecuteXmlReader();
con.Close();
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root></root>");
XmlNode node = doc.ReadNode(reader);
while(node != null)
{
Console.WriteLine(node.InnerXml);
node = doc.ReadNode(reader);
}
reader.Close();
reader = null;
doc = null;
//
}
}
}
SubashPosted Sep 7, 2016, 4:10 AM
Nice one
basit abdulPosted Nov 28, 2010, 8:53 AM
i want to create a report using sql server reporting services 2008 and pupblish to my website at a regular interval. I can create the reports but my problem is how to make it available on my website. currently, it is a static report which i manually copy and past on the site. Help me please.
saroer azamPosted Apr 26, 2010, 4:33 AM
I wanna use this in asp.net. Can you please provide me a modification for asp.net and mysql?
shaveta mehtaPosted Jun 25, 2007, 7:31 AM
HI Can u plz tell me How to fetch data from database in SQL Format. Thanks
Jayanta DuttaPosted Feb 10, 2006, 1:30 AM
hi ashish, Thanks very much for the article. I have done as you had writen in the article. but i am not getting XmlReader reader = cmd.ExecuteXmlReader();.instead it gives me XmlReader reader = cmd.ExecuteReader();. Can you tell me what is the raeson behind it? Note: i have included System.Xml and i am using oracleClient and i have included all the namespaces necessary for that. Jayanta