Solved

Import CSV Data Problem

Posted on 2006-07-13
4
1,097 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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