0

Ok, so I did some research and I'm sure this site gets asked how to fix this error at least once a day. However, I attempted to debug but I still consider myself a novice at programming and am unable to solve this error after researching it. Here is the following code in C#:

DataSet set2 = new DataSet(); //Here, the DataSet is being created
clsData data2 = new clsData();     
set2 = data2.getData("SELECT * FROM TBLREFDES WHERE reportnote  like '%must installed%'"); //Here, the DataSet is being set to something so it is no longer null    
int num94 = (set2.Tables[0].Rows.Count - 1); //Here is where the error "Object reference not set to an instance of an object" occurs

I have used an if statement to double check that both variables "set2" and "data2" are not null, and they aren't. Any help will be greatly appreciated.

1 Answers1

0

Most probably your set2.Tables[0] us null. In other words: your query somehow doesn't return any result.

And also consider to not create DataSet before, cause it will be eventually assigned by getData(..) method.

Tigran
  • 59,345
  • 8
  • 77
  • 117
  • Looks like this might be the cause. This is not my code, and the guy who wrote it left the company so I cannot ask him for help. Also, I am not familiar with DataSet. Do you have any suggestions on how to fix this? – Jared.Rodgers Nov 24 '14 at 19:35
  • @Jared.Rodgers: check for `null` – Tigran Nov 24 '14 at 19:35