Ejemplo n.º 1
0
        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.");
            }
        }
Ejemplo n.º 2
0
 // METHODS
 public void AddEmployee(Employee newEmployee)
 {
     employees.Add(newEmployee);
 }