I have a C# windows application which does the following:
1) the main form is called EmployeeForm.cs which holds 1 employee record from a sql database. I have used linq to sql to display the records.
2) There is a button on the EmployeeForm when clicked opens another form called Orders.cs which displays a datagrid of orders pertaining to the Employee ID. I am using linq to sql again to display this data.
3) I have got everything working except being able to filter the datagrid by the specific Employee ID. I assume I need some sort of where clause in the orders linq statement??
I know how to achieve this a few different ways for the web but cannot work this out for my windows app. I have included what I have so far:
public partial class EmployeeForm : Form
{
private NorthWindDataContext db;
public EmployeeForm()
{
InitializeComponent();
db = new NorthWindDataContext();
var employeeQuery = from employee in db.Employees
orderby employee.FirstName
select employee;
employeeBindingSource.DataSource = employeeQuery;
}
private void Orders_Click(object sender, EventArgs e)
{
OpenOrdersForm();
}
private void OpenOrdersForm()
{
OrderForm orderFormInstance = new OrderForm();
orderFormInstance.ShowDialog();
}
}
and
public partial class OrderForm : Form
{private NorthWindDataContext db;
public OrderForm()
{
InitializeComponent();
}
private void OrderForm_Load(object sender, EventArgs e)
{
db = new NorthWindDataContext();
var ordersQuery = from orders in db.Orders
orderby orders.OrderID
select orders;
orderBindingSource.DataSource = ordersQuery;
}
}