How to add 'Real' type to a DataTable?

后端 未结 2 479
梦如初夏
梦如初夏 2021-01-28 13:38

I am bulkcopying records from a csv file to a sql table. The sql table has columns that are varchar, and columns that are real datatype (based on the csv attributes we are given

2条回答
  •  离开以前
    2021-01-28 13:56

    I had a similar challenge after importing XML-data via .readXml because the XML included empty strings instead of dbnull. I made a lot of tests to get this converted as fast as possible and for me this worked best:

    1. create a dataTable with all columns as stings for the data-import
    2. create the same columns with slighly different names with the correct target type in the same table and create a reference to the string-column (e.g. if first column of type 'string' is named "c1" then i named the new column of type 'real' "c1_")
    3. during creation of each column in step 2 also create an expression like 'IIF(LEN([c1]=0),NULL,[c1])' that solves the "empty-string"-dilemma.
    4. now do a bulk-import and finally export only the referencing columns via a dataTableReader into its own dataTable.

提交回复
热议问题