I've seen a couple other posts on this but no real answers. I'm
trying to do a bulk insert and everything is fine until I run the
objCom.ExecuteNonQuery() statement at which point I get the XML
parsing error. Of course, it would be easy to simply wrap unicode
characters with CDATA <![CDATA[ 
 ]]> but is this doable when
passing values to fields to create a row since a whole row is treated
as a single element? I.e.:
<FileProperty File_ID_FK=\"80\" Property_Name_VC=\"Categories\"
Property_Value=\"\" Property_DataType_VC=\"olText\" />\r\n
Is there a way to set encoding to UTF-8? Any wisdom on this would be
greatly appreciated.
(Below is the offending code where I get my error)
Best,
- Rich
************************************************** ****
static void SaveThroughXML(System.Data.DataSet objDS,
System.Data.SqlClient.SqlConnection objCon)
{
DataTable tbl = objDS.Tables["PSTFiles"];
System.Text.StringBuilder sb = new System.Text.StringBuilder( 1000
);
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
foreach( DataColumn col in tbl.Columns)
{
col.ColumnMapping = System.Data.MappingType.Attribute;
}
objDS.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);
SqlCommand objCom = new SqlCommand();
objCom.Connection = objCon;
objCom.CommandType = CommandType.StoredProcedure;
objCom.CommandText = "sp_InsertBlah";
objCom.Parameters.Add( new SqlParameter( "@data",
System.Data.SqlDbType.NText));
objCom.Parameters[0].Value = sb.ToString();;
objCom.ExecuteNonQuery(); // Exception is raised here
}