I have an xml file I want to save it's content into database to read it again.
I use XmlDocument to load the xml file and using InnerXml to save this xml.
This is my code
cmd.CommandText = @"INSERT INTO pages(BPMNID,XML) VALUES (@BPMNID,@XML)";
cmd.Parameters.AddWithValue("@BPMNID",2);
cmd.Parameters.AddWithValue("@XML", XDoc.InnerXml);
cmd.Connection = conn;
conn.Open();
try
{
cmd.ExecuteNonQuery();
}
When run the previous code I get an exception
XML parsing :Unable to Switch the encoding
Hint: Xml column is a xml column
.AddWithValue()- it can lead to unexpected and surprising results...XmlDocument:..