Import of csv file into dataset problem

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
 
P

Paul Clement

¤ 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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top