VB.NET - Vb.net CSV column Types

Asked By James O'Brien on 29-Aug-12 05:21 PM
Hi,

I am trying to import a csv file and use it in a data set. One of the csv columns holds mobile numbers in, but when the csv file is imported and show in a datagrid in starting 0 is removed.

I'm importing the data from the csv file using oledb, and assume that vb.net 'sees' the mobile numbers as integer values and there removes the first 0.

Is there a way that I set the column types as strings for all columns or something like that to get around this??

The column that contains these mobile numbers will vary from time to time, and don't want to hard code a solution around a specific colum, such as adding a 0 again once the data is imported.

James
Tom Wilson replied to James O'Brien on 30-Aug-12 08:39 AM
Short of enclosing the mobile number in quotes ("0xxxxxx") in the csv file, I don't think there is a way to set a column type using OleDb.  Another option would be to use a streamreader, split the row based on the delimiter, and load the datatable.
Tom Wilson replied to James O'Brien on 30-Aug-12 11:29 AM
You can use a Schema.ini file to define the data types in a csv. file.  See this link:

http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx