问题
I am inserting data into SQL 2005 using SQLXMLBulkLoad.SQLXMLBulkload.3.0
My data table has following column:
objDataTable.Columns.Add("TaskDateTime", System.Type.GetType("System.DateTime"))
My bulk insert schema has following definition:
<xsd:element name="DepartureTime" type="xsd:date" />
(Using xmlns:xsd="http://www.w3.org/2001/XMLSchema")
And I am getting 'Invalid character value for cast specification' exception.
Any advice?
回答1:
Solved!.
Changed column type from: objDataTable.Columns.Add("TaskDateTime", System.Type.GetType("System.DateTime")) to objDataTable.Columns.Add("TaskDateTime", System.Type.GetType("System.String"))
and I am storing my value as .ToString("yyyy-MM-dd HH:mm") + ":00+00:00" in the data table. when creating XML file on disk, it simply writes it as string and the schema file for bulk insert reads it as datetime.
回答2:
The problem is blanks in the source columns........ this is what is causing the invalid character value for cast specification.
来源:https://stackoverflow.com/questions/4032887/invalid-character-value-for-cast-specification