Error: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized)

excel
activities
error

#21

This means that there is no data in the table or it has not been initialized before writing into the excel. Do make sure that you have data in datatable


#22

In my case, when there is no data in the datatable then it should return back successfully. But still it is throwing the error while returning back. How to solve this?


#23

Write a check if DataTable.Rows.Count>0 then only it should proceed