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

x
?
Solved

Leading zeroes in a zip code column get stripped out

Posted on 2011-03-14
7
Medium Priority
?
741 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
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!

 
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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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