Import of csv file into dataset problem

  • Thread starter Thread starter twq
  • Start date Start date
T

twq

Hello

I would like to import a csv file into a dataset,

In one column i have a mix of string and numeric values, the problem
is that somehow only the numeric values are imported and all string
values are imported as null values, what i want is that all values are
imported as string values. Does anyone has an idea how to do that?

here is the code:

Function GetCVSFilePrice(ByVal pathfile As String)

Dim CSVConnection As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
pathfile & ";Extended Properties=Text")
Dim CSVCommand As OleDbCommand = New OleDbCommand("SELECT
DISTINCT instr_code, ptf_date, today_price FROM " & pathfile ,
CSVConnection)

Dim CSVAdapter As OleDbDataAdapter = New
OleDbDataAdapter(CSVCommand)
Dim CSVDataSet As DataSet = New DataSet()

Try
CSVConnection.Open()
CSVAdapter.Fill(CSVDataSet)
CSVConnection.Close()

Catch
CSVDataSet = Nothing
End Try

Return CSVDataSet
CSVDataSet.Clear()

End Function
 
¤ Hello
¤
¤ I would like to import a csv file into a dataset,
¤
¤ In one column i have a mix of string and numeric values, the problem
¤ is that somehow only the numeric values are imported and all string
¤ values are imported as null values, what i want is that all values are
¤ imported as string values. Does anyone has an idea how to do that?

Yes, you have to create a schema.ini to define your column data types. The mix mode column would
need to be defined as Text:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top