Solved

Import CSV Data Problem

Posted on 2006-07-13
4
1,095 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 125 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 39
No Data for DropDown List 2 29
VB.NET 2008 - SQL Timeout 9 34
Groupbox Control ? 2 20
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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