I have the following code:
DataClasses1DataContext db = new DataClasses1DataContext();
var UserInfo = db.Users.FirstOrDefault(u => u.Email == TextBox1.Text);
if (UserInfo.Email != null)
{
Label2.Text = "Email is not null";
}
else
{
Label2.Text = "Email is null";
}
If an e-mail address exists in the table, it successfully prints "Email is not null." However, if there is no matching record, I then receive an Object reference not set to an instance of an object error for Line 29:
Line 27: DataClasses1DataContext db = new DataClasses1DataContext(); Line 28: Line 29: var UserInfo = db.Users.FirstOrDefault(u => u.Email == TextBox1.Text); Line 30: Line 31: if (UserInfo.Email != null)
I'm stumped! Any help would be greatly appreciated.