How to pass XML data type to Datatable when inserting data through SqlBulkCopy for SQL server?

In my application, I want to insert an XML document into my table that has a column with an XML data type. Now the problem occurs when I use SqlBulkCopy in my application. I need to pass the Datatable to SqlBulkCopy.WriteToServer method. it shows me an InvalidCastException. To store the XML data in a datatable, I tried to use the Datatype DataColumn property and set it to XmlReader (did not work), XElement (did not work) and a line that shows an InvalidCastException.

So, I want to know what data type I should specify for a DataColumn so that data can be inserted using sqlbulkcopy.

Thank,

+3
source share
1 answer

Try sending xml as string type

0
source

Source: https://habr.com/ru/post/1765769/


All Articles