0
votes

Hello guys am having a problem while reading data from excel using Jet oledb in my MVC web application. My application has an option to upload excel file

Here is my code for constructing connection string

if (0 == extension.CompareTo(".xls"))
{
                connString = ConfigurationManager.ConnectionStrings["MicrosoftProviderForxls"].ConnectionString +
                   fileName + ConfigurationManager.ConnectionStrings["MicrosoftPropertyForxls"].ConnectionString;
}

The value of connectionstring is

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\20_18_18_26.xls;Extended Properties=Excel 8.0"

Which works fine giving me number of rows read correctly. The issue occusrs when delete some rows from that excel file by selecting some rows and pressing "Backspace" or using delete option in excel

Here the number of rows read is returning as incorrect as if no rows are deleted.

How can I solve this? Do I Need to add any parameters to connection string to make sure that empty rows are not counted

1

1 Answers

0
votes

I tried something like this

var isEmpty = row.ItemArray.All(x => x == null || (x != null && String.IsNullOrWhiteSpace(x.ToString())));  
if (isEmpty)
{
    emptyRow++;
    continue;
}

Also I tried to give IMEX =1 in conenction string but it didn't worked out so I opted for the above code. Would be better if "IMEX" parameter worked