How to pass XML content as Parameter to back end in asp.net?

How to pass XML content as Parameter to back end in asp.net?

here strXML is input parameter. here we are going to write XML content into Sql server 2005.



protected void XMLWRITER(string strXML)
{
try
{
string strCon = "server=myServer;database=myDB;User ID=vbtc;Password=vbtc";
string strSql = "UPDATE Sites SET Categories = @Categories where SNo = @SNo";
SqlConnection objCon = new SqlConnection(strCon);
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSql;
SqlParameter objParaSNo = new SqlParameter("@SNo", System.Type.GetType("System.Int32"));
SqlParameter objParaCategory = new SqlParameter("@Categories", System.Type.GetType("System.Xml"));
objCmd.Parameters.Add(objParaSNo);
objCmd.Parameters.Add(objParaCategory);

objParaSNo .Value = int.Parse(txtSNo.Text);
objParaCategory.Value = strXML;
objCmd.ExecuteNonQuery();

objCon.Close();
}
catch (Exception ee)
{
Response.Write(ee.Message + " " + ee.StackTrace);
}
}

No comments: