选择“第一个或默认值绑定到网格视图窗口窗体 C#”
本文关键字:窗口 视图 窗体 网格 第一个 默认值 绑定 选择 | 更新日期: 2023-09-27 18:31:16
我正在尝试将 SQL 数据库表中的前 1 个值绑定到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;
}
}
尝试以下
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();
不能将一个项绑定到网格视图。 从项目创建列表并将其设置为数据