Home All Groups Group Topic Archive Search About

Import of csv file into dataset problem

Author
2 Feb 2007 5:42 PM
twq@hispeed.ch
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

Author
5 Feb 2007 5:22 PM
Paul Clement
On 2 Feb 2007 09:42:03 -0800, "t**@hispeed.ch" <t**@hispeed.ch> wrote:

¤ 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)
Author
9 Feb 2007 10:03 AM
twq@hispeed.ch
Vielen Dank für die Hilfe,

Gruss
Tobias

AddThis Social Bookmark Button