-2

I get the message "Object reference not set to an instance of an object" when clearing a data table.

Ds.tables["table_name"].Clear();

The datatable exists and it contains data.

Thanks for your help.

Zeeshan Adil
  • 1,937
  • 5
  • 23
  • 42

2 Answers2

0

It's about your object not database, you need to check Ds and then Ds.tables["table_name"] to if they are null then call Ds.tables["table_name"].clear();

Sina
  • 575
  • 1
  • 5
  • 23
0

Add condition

if(Ds.tables["table_name"]!=null){
   Ds.tables["table_name"].Clear();
}

OR

if(Ds.tables["table_name"]!=null){
   Ds.Rows.Clear();
}
Ashfaque Ali Solangi
  • 1,883
  • 3
  • 22
  • 34