Invalid character value for cast specification

痴心易碎 提交于 2019-12-11 03:39:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!