I am using Visual Studio 2010 and SQL Server 2008. I need to create a XML file which looks like:
<cat>
<name> "Categories"</name>
<link> "link"</link>
</cat>
The Categories and link values should be added from the database.
I have tried everything but I cannot get it to work. DO I have to create a XML file in ASP to do this?
These values are in the same table but there are other columns in the table as well.
My code looks something like this:
SqlCommand sqlcmd = new SqlCommand();
//sqlcmd.CommandText = "Select * from Categories";
DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select * from Categories", "Data Source=something;Initial Catalog=My Database;Integrated Security=True");
da.Fill(ds);
int rows;
rows = ds.Tables[0].Rows.Count;
int i;
for (i = 0; i <= rows - 1; i++)
{
string Categories = ds.Tables[0].Rows[i].ItemArray[0].ToString();
string address = "https://www.something.com/";
string link = address + ds.Tables[0].Rows[i].ItemArray[1].ToString();
}
ds.WriteXml(@"c:\output.xml", XmlWriteMode.WriteSchema);
Can someone please give me a detailed solution to this problem.
Thank you