Tuesday, 6 August 2013

why Object reference not set to an instance of an object.?

why Object reference not set to an instance of an object.?

hi why this error is happened on **?
error : Object reference not set to an instance of an object.
public static long GetID(string str1, string str2)
{
using(MyContext db = new MyContext())
{
**long Idold = db.old.FirstOrDefault(p => p.oldfield ==
str1).id;**
return db.tbl_new.FirstOrDefault(p => p.id_old == Idold && p.newfield
== str2).id;
}
}
of course my tbl isn't empty .i set values to str1 and str2 that are exist
in my tbl.

No comments:

Post a Comment