Solved

Leading zeroes in a zip code column get stripped out

Posted on 2011-03-14
7
736 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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