Solved

Leading zeroes in a zip code column get stripped out

Posted on 2011-03-14
7
717 Views
Last Modified: 2012-06-27
I have a csv file with which contains a zip code column. When I import this csv file into a data table any zip code with a leading zero has the leading zero stripped out.
How can I avoid this ?

Thanks,
Aditya
0
Comment
Question by:pmac38CDS
  • 3
  • 3
7 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 35130500
can you make it a string field, if it isn't already?
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 35130669
The data table is of the type DataTable.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 35130685
is the zip code column a string?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:pmac38CDS
ID: 35130856
I am using a generic DataTable to import the csv into.
DataTable dt = new DataTable()
0
 
LVL 22

Expert Comment

by:p_davis
ID: 35130860
ok then, how, exactly, are you importing the file into the generic datatable?
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 35130984
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +";Extended Properties=Text;";
            OleDbConnection objConn = new OleDbConnection(sConnectionString);
            objConn.Open();
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM " + fileName, objConn);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
   
            objAdapter1.Fill(dtMain);
            int count = dtMain.Rows.Count;
           
            objConn.Close();
           
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 35131949
The zip code column is being interpreted as a number by the Jet database engine, not text, and hence leading zero's are lost.  You can use a schema.ini file to specifically specify the data types of the columns (i.e. you can force the zip code column to be interpreted as text): http://msdn.microsoft.com/en-us/library/ms709353(VS.85).aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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