this code will generate XML file for the database entry which will useful to access in web application
steps:
Import following namespace
using System.Xml;
using System.Data.Sql;
[WebMethod]
public XmlElement GetUserDetails(string str1)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["NewsConnection"].ToString());
con.Open();
cmd = new SqlCommand("select * from NewsData where NewsCategory like @str1 + '%'", con);
// dr = cmd.ExecuteReader();
// cmd.Parameters.AddWithValue("@News", NewsHeadline);
cmd.Parameters.AddWithValue("@str1", str1);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Create an instance of DataSet.
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
// Return the DataSet as an XmlElement.
XmlDataDocument xmldata = new XmlDataDocument(ds);
XmlElement xmlElement = xmldata.DocumentElement;
return xmlElement;
}
}
steps:
Import following namespace
using System.Xml;
using System.Data.Sql;
[WebMethod]
public XmlElement GetUserDetails(string str1)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["NewsConnection"].ToString());
con.Open();
cmd = new SqlCommand("select * from NewsData where NewsCategory like @str1 + '%'", con);
// dr = cmd.ExecuteReader();
// cmd.Parameters.AddWithValue("@News", NewsHeadline);
cmd.Parameters.AddWithValue("@str1", str1);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Create an instance of DataSet.
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
// Return the DataSet as an XmlElement.
XmlDataDocument xmldata = new XmlDataDocument(ds);
XmlElement xmlElement = xmldata.DocumentElement;
return xmlElement;
}
}