0

我正在尝试将我的 SQL 数据库表中的前 1 个值绑定到 a GridView,但它没有显示:

private void btnSubmit_Click(object sender, EventArgs e)
{
    WireLine_Tracking_AssetsDataContext doc = new WireLine_Tracking_AssetsDataContext();

    if (txtCustomerInvoiceNo.Text != string.Empty )
    {
        var query = (from b in doc.WireLine_Movements 
                     where b.CustomerInvoiceNo.Contains(txtCustomerInvoiceNo.Text.Trim())
                     orderby b.ID descending
                     select new { b.AssetCode, b.CustomerInvoiceNo, b.CurrentLocation,
                                  b.FromLocation}).FirstOrDefault();
        dgvresult.DataSource = query;
    }
}
4

1 回答 1

1

试试下面

var query = (from b in doc.WireLine_Movements 
                     where b.CustomerInvoiceNo.Contains(txtCustomerInvoiceNo.Text.Trim())
                     orderby b.ID descending
                     select new { b.AssetCode, b.CustomerInvoiceNo, b.CurrentLocation,
                                  b.FromLocation}).Take(1).ToList();

您不能将一项绑定到网格视图。从项目创建列表并将其设置为数据源

于 2013-09-13T13:24:54.293 回答