Solved

Leading zeroes in a zip code column get stripped out

Posted on 2011-03-14
7
728 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

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 This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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