Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Import CSV Data Problem

Posted on 2006-07-13
4
Medium Priority
?
1,111 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 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

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 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