I have three columns in an Excel sheet:
- CompanyName
- PhoneNo
- EmailId
When I try to fetch data from Excel, if the sheet contains 012-231564
type of data in PhoneNo
column, then the resulting DataSet contains blank cell
var connString = string.Format("Provider=Microsoft.Jet.OleDb.4.0;
Data Source={0};Extended Properties=\"Text;HDR=YES;FMT=Delimited\"",
Path.GetDirectoryName(Server.MapPath("~/DataMiningFiles/" + StrFileName)));
var query = "SELECT * FROM [" + Path.GetFileName(Server.MapPath("~/DataMiningFiles/" + StrFileName)) + "]";
using (var adapter = new OleDbDataAdapter(query, conn)) {
var ObjGetExcelData = new DataSet("CSV File");
adapter.Fill(ObjGetExcelData);
}
There's quite a bit I'd change about this tbh. So lets see...
Generally I'd read this table by table. I'm not familiar with your attempt to read the lot into a DataSet. I may have a go if I get bored over the new year. This example will however work...
Incidentally please try to avoid the use of "var" variables. Strongly type them and you will save yourself and others much heartache later on.
If you know the name of the sheet you want to read you can simply code it all as...