473,695 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing leading zeros on parsed CSV File - Schema.ini not working for me

Hi All,

I am having a problem with leading zeros being stripped from fields in a CSV
file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing
a CSV file like so:

sSQL = "SELECT * FROM [" & sFileName & "]"
sConnStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
Microsoft.Visua lBasic.FileIO.F ileSystem.GetPa rentPath(msFile ) &
"\;Extended Properties=""te xt;HDR=No;FMT=D elimited"";"

CreateSchemaIni File(sFileName, sPath) 'creates my Schema.ini file

oConn = New System.Data.Ole Db.OleDbConnect ion(sConnStr)
oDA = New System.Data.Ole Db.OleDbDataAda pter(sSQL, oConn)
With FileSystem.Open TextFieldParser (msFile)
msFileHeader = .ReadLine()
End With

To set each column to a text format so I can retain any leading zeros, I
dynamically create a Schemal.ini file that looks something like this (first
few rows):

[ImportMe_TestLe adingZero.csv]
Format=CSVDelim ited
ColNameHeader=F alse
CharacterSet=OE M
Col1="PersonID" Char
Col2="First Name" Char
Col3="Middle Name" Char
Col4="Last Name" Char

In the Schema.ini file, I have tried both "Char" and "Text" as the format
descriptor for each column.

My simplified CSV file looks like this:

"PersonID","Fir st Name","Middle Name","Last Name"
00334,Jimbo,J,J ones

With this setup, if I reference the first field, the PersonID comes in as
334. However, if I change my CSV by putting double quotes arround the
PersonID value (like "00334"), it then comes in correctly with the leading
zeros. Unfortunately I have no control over the source file so I cannot add
the double-quote field qualifiers. Can anyone tell me if there is a way to
bring the values correctly with the leading zeros? For what it's worth, I've
also set the registry key like this (below), but to no avail:

Hkey_Local_Mach ine/Software/Microsoft/Jet/4.0/Engines/Excel/ImportMixedType s=Text

TIA for your help.
Oct 3 '08 #1
0 4097

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: david | last post by:
Hi, I have an application as follows: MySQL database Back-Eend linked to MS Access Front-End and ASP Web Application. I require users to enter Serial Numbers such as: 0105123567 (10 digits), the first 4 being the month and year (mmyy)
by: david | last post by:
Hi, I have 2 text boxes on an ASP form. A user enters a Serial Number in TB1 such as 0105123456, presses tab to move to TB2, TB2 then displays the value of TB1 after a calculation has been done. (Based on a Serial Number range). i.e. a user enters 0105123456, TB2 then adds 'x' qty to this number depending on how many serial numbers are required.
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros are needed. I've formated the field to be a text field, general number, and number and still I get the #num! error, or the leading zero is dropped. Can someone help before I pull more of my hair. Thanks a bunch.
by: Joshua Ammann | last post by:
Hello, I'm trying to export a query containing contact information, including a field. Some zip codes have one or two leading zeros, for example, San Juan, PR (00927) and Springfield, MA (01104). When I export to a comma separated value (.csv) file, the zip code for San Juan becomes "927" and for Springfield becomes "1104". How can I prevent the leading zero(s) from being trimmed in the exported .csv file? Because the table contains...
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a SpecificationName via the Export Wizard without success. Obviously doing something wrong.
by: OneDay | last post by:
I've got a field that has some old data with text in it, but all forward data will be a 3 digit number. But many of the numbers are still only 2 digits. I would like to force the leading zero in the entry of the field. For example if the number 77 is entered into the field, 077 will display. How do I format to force the leading zero?
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function doesn't create leading zeros. The Format function (format(value,"X") doesn't create leading zeros. I believe there should be a simple way that doesn't involving measuring and padding the string.
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.