private void cmdGetEmployee_Click(object sender, RoutedEventArgs e) { int ID; if (Int32.TryParse(txtID.Text, out ID)) { try { // query with LINQ var query = from emp in db.Employees where emp.EmployeeId == ID select emp; // same query using LINQ lambda expression //var query = db.Employees.Where(emp => emp.EmployeeId == ID); employee = query.First(); gridEmployeeDetails.DataContext = employee; } catch (Exception ex) { MessageBox.Show("Error contacting database." + ex.Message); } } else { MessageBox.Show("Invalid ID."); } }
// METHODS public void AddEmployee(Employee newEmployee) { employees.Add(newEmployee); }