Thursday, July 26, 2012

Connection String and Select Statement of Excel File in .Net Application

Microsoft provider two Data Provider to extract Data from Excel Files

the first one will have the connection pointing the folder or path that the file reside. the select command text will be select specific columns from the excel file.

 string ConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0} ; 
Extended Properties=""Text;HDR=NO;FMT=Delimited;IMEX=1;"";"importPath);

 string SelectRateCommandText = string.Format("select * from [{0}]" 
Path.GetFileName(importFilewithPath));


the second provider will have the connection pointing the actual file and select command text will
be select all specific columns from the sheets in the excel file.

string ConnectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0} ; 
Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1;"";", importFilename);

string selectCommandText = "select * from [Sheet1$]";

for the second option, when you work with it in asp.net web application,
you must upload the excel file the local temp folder first, then extract
the data.finally you can move it to the archive network folder. you can
directly pointing to the network folder and extract the data due to the
security issue. 





No comments:

Post a Comment