private void OnCreated(object sender, FileSystemEventArgs e)
{
excelDataSet.Clear();
string extension = Path.GetExtension(e.FullPath);
if (extension == ".xls" || extension == ".xlsx")
{
string ConnectionString = "";
if (extension == ".xls") { ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = '" + e.FullPath + "';Extended Properties=\"Excel 8.0;HDR=YES;\""; }
if (extension == ".xlsx") { ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = '" + e.FullPath + "';Extended Properties=\"Excel 12.0;HDR=YES;\""; }
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
conn.Open();
OleDbDataAdapter objDA = new OleDbDataAdapter("select * from [Sheet1$]", conn);
objDA.Fill(excelDataSet);
conn.Close();
conn.Dispose();
}
}
}
This is my code. It's working when my filewatcher triggers. Problem is the excel file I read has 1 header row and 3 row that has values. When I use this code and check my dataset row count I get 9.. I've no idea where does it take that 9 from, am I doing something wrong? I'm checking my code for last 30-35 min and still couldn't find what I'm doing wrong.. I get the column's right but the rows are not working. I don't need the header line btw
Update: my example excel file had 3 rows and I was getting 9 as row count. I just copied these rows and made my file 24 row + 1 header row and when I did rows.count I got 24 as answer. So it worked fine? Is that normal?