I have a CSV that I am reading into a datatable using ADO.NET. One of the columns has a problem. The value in the column happens to be 10-05-20. That looks like a date, but it is not. It's just a string.

ADO interpreted the value as a date, so when I imported the data with SELECT *, it turned that column into a date field, which broke the program that was not expecting a date.

The first thing I tried was explicitly adding the column to the datatable with a datatype of String. That was the only column I was adding, so I wasn't sure it would work, but it did...sort of. ADO.NET correctly added all the other columns, and put the data into the column in question, but stuck it in there as a date...that had been turned into a string. That broke the program, as well.

So, what I'm looking for is a way to select everything from a CSV where one field may look like a date, but is actually not at all a date, and if it is converted into a date, then bad things happen.

I tried SELECT CAST(<my field here> AS varchar)

and SELECT CONVERT (varchar, <my field here>)

The first resulted in an error I didn't understand (IErrorInfo.GetDescription failed with E_FAIL(0x80004005).), while the second said that CONVERT was not a recognized function.

How can I stop ADO from seeing that text string as a date?