views:

719

answers:

2
 var result = from lr in _db.LeaveRequest
                 join th in _db.TotalHourslu    
                 on lr.TotalHoursEffect 
                 equals th.Minutesselect
                     select new { lr.TotalHoursEffect, th.Minutes, tr.Display };

ERROR: The name '_db' does not exist in the current context The name '_db' does not exist in the current context The name ' tr ' does not exist in the current context

A: 

Did you forget to add

MyDataClassesDataContext _db = new MyDataClassesDataContext();

to your class as a member variable?

Robert Harvey
Hi Robert, thank you. I forgot to put the above datacontext. I added the above and I am still having error on: tr.Display.
Kombucha
+1  A: 

That error means there are no objects named _db or tr accessible in the current context. This means there are no method-local, class-member or global variables with those names. Did you possibly copy-paste some code and forgot to rename the variables to the correct names?

Also remember that member variables in one class are not accessible from other classes unless you prefix them with "ClassName.", like NameOfClassWhereDBIsDefined._db. And that won't even work if _db is a private member, like it probably is. In that case, you would have to pass _db in as a parameter to the function, or have it accessible through a getter method/property.

Sean Nyman
Hi Darth, thank you. Got it!
Kombucha