Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Import CSV Data Problem

Posted on 2006-07-13
4
Medium Priority
?
1,123 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
ID: 17100803
what's the error that you are getting?
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 17101296
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
ID: 17102702
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
ID: 17106815
changing the reg key ImportMixedTypes to Text appears to have fixed the issue.

thanks

Brian
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

879 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