I'm new to C# and ASP.NET
I managed to put MS SQL Server database into xml document, but what I'm trying to do now is, to add an attribute to the XML, which will be an id from the database.
something like:
<Products>
<product id=1>
<name>Some name</name>
</product>
<product id=2>
<name>Some other</name>
</product>
<product id=3>
<name>Some other name</name>
</product>
</Products>
This is what I have so far:
products.asmx.cs:
[WebMethod]
public XmlDocument productsAll()
{
string conString = "Data Source=my_db.com;Integrated Security=True";
SqlConnection sqlConn = new SqlConnection(conString);
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "SELECT * FROM Products";
SqlDataAdapter dataAdptr = new SqlDataAdapter();
dataAdptr.SelectCommand = sqlCmd;
DataSet dsProducts = new DataSet("Products");
dataAdptr.Fill(dsProducts, "product");
XmlDocument xmlDom = new XmlDocument();
xmlDom.LoadXml(dsProducts.GetXml());
return xmlDom;
}
.asmxweb services are dead - check out either WCF or the new ASP.NET WebAPI for REST services