Leading zeroes in a zip code column get stripped out

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
LVL 1
pmac38CDSAsked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
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
 
p_davisCommented:
can you make it a string field, if it isn't already?
0
 
pmac38CDSAuthor Commented:
The data table is of the type DataTable.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
p_davisCommented:
is the zip code column a string?
0
 
pmac38CDSAuthor Commented:
I am using a generic DataTable to import the csv into.
DataTable dt = new DataTable()
0
 
p_davisCommented:
ok then, how, exactly, are you importing the file into the generic datatable?
0
 
pmac38CDSAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.