Samio

Samio

  • NA
  • 201
  • 176.4k

LINQ to Entities - How to retrieve a data and use it as a variable in the whole project

Mar 21 2012 7:42 AM
Hi,

I have 1 WinForm and 2 tables:

- Form1  contains   TextBox1

- Employee  contains     ID, LastName, FirstName, BirthDate.
- Tasks  contains   ID, TaskName


I need to input LastName and FirtName in TextBox1 to retrieve the related "TaskName" if exists,
then make the retrieved data usable from any location in the project

I need to know where to put the TaskName variable?
and how can I modify the next code to reach that purpose?

using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
ObjectQuery<Employee> Employee = MyEntities.Employee;
var query = (from p in Employee
where p.FirstName == TextBox1.Text.Trim()
select p.LasttName, p.FirstName);
}
Thanks

Answers (3)