User-986267747 posted
Hi sreekanth.jonna,
I am getting error on Tables[0]
DataTable filteredRows = ExcelReaderNew.ExcelToDataTable(fileName); DataTable FilteredRows = filteredRows.Tables[0].Rows.Cast<DataRow>()
A DataSet holds an array of DataTables, and it can have 0, 1 or many of these DataTables. You access them just like any other array - by indexing into them. But the filteredRows is a datatable variable and it don't contain multiple instances of Table. So
when you use filteredRows.Tables[0] property, you get the error message. You should modify you code , like this.
DataTable FilteredRows = filteredRows.Rows.Cast<DataRow>()
.Where(row => !row.ItemArray.All(field => field is System.DBNull))
.CopyToDataTable();
If you want to get more information about dataset and datatable, you could refer to the following links.
https://msdn.microsoft.com/en-us/library/system.data.datatable%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
https://msdn.microsoft.com/en-us/library/system.data.dataset%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Besides, for your requirement, you'd like to remove these empty rows and to insert only data into database from excel sheet, isn't it? you could refer to the following link.
http://stackoverflow.com/questions/7023140/how-to-remove-empty-rows-from-datatable
I hope it's helpful to you.
Best Regards,
Klein zhang