0

hi can anybudy temme the reason of this error

my code is

DataClassesDataContext dc = new DataClassesDataContext();
 tblUser tu = new tblUser();
           
            var res = (from p in dc.tblUsers where p.nUserID == _index select p).FirstOrDefault();
           

            res.strUserName = txtUserName.Text;
            res.strPassword = txtPassword.Text;
            res.dAddDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            res.bIsDeleted = false;

it is giving me dis exception on

res.strUserName = txtUserName.Text;

why its so:((

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by __avd
0

Check the null.

var res = (from p in dc.tblUsers where p.nUserID == _index select p).FirstOrDefault();
           
 if(res!=null)
  {
            res.strUserName = txtUserName.Text;
            res.strPassword = txtPassword.Text;
            res.dAddDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            res.bIsDeleted = false;
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.