Question : Importing CSV into DataTable datatype problem  VB 2010

Hi

Im importing a CSV file into a datatable, it all goes well, except that I have a few columns that have rows which contain eaither a number or "????" . Unfortunatly the code that I have converst this column of data into double and my "????" are then turned into zero.

I would like to change the data columns datatype but I havent been able to do so even though I change the type prior to filling the table (see code). how do force the columns to be read as text ?

Michal
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path.GetDirectoryName(CSVName) & "\;Extended Properties=""text;HDR=YES;FMT=Delimited"""
            Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
            Dim da As OleDb.OleDbDataAdapter



            'Open Data Adapter to Read from Text file
            Dim str As String = "SELECT * FROM [" & Path.GetFileName(CSVName) & "]"
            da = New System.Data.OleDb.OleDbDataAdapter(str, objConn)
            'Fill dataset using dataadapter
            da.FillSchema(SystemTable, SchemaType.Mapped)

            For Each column As DataColumn In SystemTable.Columns
                If column.ColumnName = "WINDIV" Then column.DataType = System.Type.GetType("System.String")
                If column.ColumnName = "PLCDIV" Then column.DataType = System.Type.GetType("System.String")
                If column.ColumnName = "SPDIV" Then column.DataType = System.Type.GetType("System.String")

            Next

            da.Fill(SystemTable)
            objConn.Close()

Answer : Importing CSV into DataTable datatype problem  VB 2010

At least you are making progress!  
1.  If column is alphanumeric, try replacing "Char" with "varChar"
2.  If column is numeric, try using Double,numeric and decimal, float and real, or money

refer to the link I gave you for questions about data types in .Net
Random Solutions  
 
programming4us programming4us