in my expense class, branch id is a foreign key. to display I got data from Sql about expense detail along branch id, branch description. Trying to set virtual property (branch) with branch description.
Asked
Active
Viewed 299 times
0
-
https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Hans Kesting May 09 '20 at 12:17
-
a) Please don't post [images of code](http://idownvotedbecau.se/imageofcode); b) on what line do you get that exception? – Hans Kesting May 09 '20 at 12:18
-
I got error on expense.Branch.Oid – Manpreet Narang May 09 '20 at 12:28
-
1Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Hans Kesting May 09 '20 at 13:53
-
You should include your database table and your query. – Jerdine Sabio May 09 '20 at 18:11
1 Answers
0
Branch branch = new Branch();
branch.Oid = (int)reader["br_oid"];
branch.Description = (string)reader["br_description"];
expense.Branch = branch;
solved my problem.

Manpreet Narang
- 95
- 1
- 1
- 8