Add the following code on the page load:
string connectionString = "Data Source=name;Initial Catalog=db name;Integrated Security=True";
DataTable d_t = newDataTable();
SqlConnection conn = newSqlConnection(connectionString);
using (conn)
{
SqlDataAdapter adp = newSqlDataAdapter("SELECT * from tablename", conn);
adp.Fill(d_t);
}
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter Text_Writer = newXmlTextWriter(Response.OutputStream,Encoding.UTF8);
Text_Writer.WriteStartDocument();
//Below tags are mandatory rss
Text_Writer.WriteStartElement("rss");
Text_Writer.WriteAttributeString("version","2.0");
// Channel tag will contain RSS feed details
Text_Writer.WriteStartElement("channel");
Text_Writer.WriteElementString("title"," ASP.NET ");
Text_Writer.WriteElementString("link","http://nehaprogrammer.blogspot.com");
Text_Writer.WriteElementString("description"," C#.NET,ASP.NET ");
Text_Writer.WriteElementString("copyright","Copyright 2013 - 2014 nehaprogrammer.blogspot.com. All rights reserved.");
foreach (DataRow oFeedItem in d_t.Rows)
{
Text_Writer.WriteStartElement("item");
Text_Writer.WriteElementString("title", oFeedItem["Title"].ToString());
Text_Writer.WriteElementString("description", oFeedItem["Description"].ToString());
Text_Writer.WriteElementString("link", oFeedItem["URL"].ToString());
Text_Writer.WriteEndElement();
}
Text_Writer.WriteEndElement();
Text_Writer.WriteEndElement();
Text_Writer.WriteEndDocument();
Text_Writer.Flush();
Text_Writer.Close();
Response.End();