Wednesday, May 20, 2009

Loading excel data column (alpha-numeric) using OLE DB adapter

Problem: One of the excel data column has alpha-numeric data stored. While loading the data using Ole DB adapter, adapter preset the data type to numeric and subsequently doesn't read the alpha numeric content.

Solution: While defining the connection string, define it as:
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";
connectionString += "data source='C:\Temp\FileTobeProcessed.xls';";

we generally define the extended properties = 'Excel 8.0;' only and forget to add, if excel file has header, or treat the column data type as alpha-numeric (add IMEX=1 in extended properties).

It helped me a lot of places, mostly, when I used Dynamics GP eConnect to transfer Items from One bin location to another, and item number data was alpha-numeric.