Solved

Import CSV Data Problem

Posted on 2006-07-13
4
1,089 Views
Last Modified: 2009-02-27
Hi,

I'm having trouble importing data from a column from a CSV file. The column causing the problem, CustomerOrderNumber can be numeric or alphanumeric. In the sample file I'm trying to import (supplied by a 3rd party), the first row contains a customer order number of 123456, the second row contains X123456. The first row imports fine, however the second row is read as DBNULL.

I use the following code to open the file:

        Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & Server.MapPath("\") & "CRMAdmin\Uploads\" & ";" & _
        "Extended Properties=""Text"""
        Dim objConn As New OleDbConnection(sConnectionString)
        objConn.Open()

        Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & strFilename, objConn)
.
.

I've imported Excel data before with no problem, after changing the registry setting HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows to 1000 (this allows Jet to determine the datatype of the column).

For the CSV text import I've changed "MaxScanRows" to 1000 to no avail.

Is there any other setting I should change to import this CSV text file successfully?

Under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\
what are the following keys and allowed values?
- ImportFixedFormat
- ImportMixedTypes
0
Comment
Question by:obyapka
4 Comments
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
what's the error that you are getting?
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 125 total points
Comment Utility
The problem you're running into is that, as you mention, Jet is determining the datatype of the column. if the majority of cells checked in a column is numeric, Jet assumes the entire column is numeric and gives DBNULL for the rest. (And if the majority is text, it may turn the numerics into nulls!). That obviously isn't a good thing if you have some of each.

I haven't tried to do this kind of an import in VB .Net. In Excel VBA, there's an option to specify whether a column should be treated as numeric or character data, though I found that I had to rename a .CSV file to .TXT or .PRN to get leading zeroes to be retained as text. However, MSKB article 257819, as well as other resources online, suggest that

ImportMixedTypes=Text

will give you what you want, reading all of the data in that column as text if any of the items are text. Note that if all items are numeric, the column will still be numeric. You also need to put the setting "IMEX=1" in the Extended Properties of the connection string, to get Jet to look at the ImportMixedTypes setting.
0
 
LVL 5

Expert Comment

by:nickhoggard
Comment Utility
Hi,

If you know the schema of the file you are importing, you could setup a schema.ini file to specify the data types of each column manually:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp

Hope this helps

Cheers

Nick
0
 
LVL 1

Author Comment

by:obyapka
Comment Utility
changing the reg key ImportMixedTypes to Text appears to have fixed the issue.

thanks

Brian
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now