显示所选行的详细信息

时间:2015-07-20 12:22:46

标签: c# linq entity-framework

我有一个窗口表单,包含2个datagridview,customer和order。当客户单元格被双击时,我想获取当前行customerID并查询具有相同customerID的nw.orders。不幸的是,LINQ结果总是返回空。我可能哪个部分做错了?或者是否有其他替代方法来检索该特定客户的订单?感谢您提前查看和建议。

public partial class CustomerOrder : Form
{
    northwindEntities nw;

    public CustomerOrder()
    {
        InitializeComponent();
    }

    private void CustomerOrder_Load(object sender, EventArgs e)
    {
        nw = new northwindEntities();
        customerBindingSource.DataSource = nw.Customers;
    }

    private void customerDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        string CustID = (string)customerDataGridView.Rows[e.RowIndex].Cells[1].Value;

        ordersBindingSource.DataSource = from order in nw.Orders
                                         where order.Customer.CustomerID == CustID
                                         select order;
    }
}

0 个答案:

没有答案