gpt4 book ai didi

c# - 选择事务,只显示一行,但在数据库中有多行

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:43 25 4
gpt4 key购买 nike

在这个空白处,我选择了交易。例如,数据库中有 3 行的 PONo 为 17,我想在 ListView 中只显示一行。可能吗?

void GetSupply()
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Supplier.SupplierName, PurchaseOrder.PONo, PurchaseOrder.PODate, " +
"PurchaseOrder.PODateReceived, PurchaseOrder.PODeliveryDate, PurchaseOrder.POPaymentMethod, " +
"PurchaseOrder.POReceiptNo, PurchaseOrderDetails.POAmount, PurchaseOrder.POPaymentDate, " +
"PurchaseOrder.POStatus FROM PurchaseOrder INNER JOIN PurchaseOrderDetails " +
"ON PurchaseOrder.PONo = PurchaseOrderDetails.PONo INNER JOIN Supplier ON " +
"PurchaseOrder.SupplierNo = Supplier.SupplierID " +
"ORDER BY PurchaseOrder.PODate DESC";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "PurchaseOrderDetails");
lvPO.DataSource = ds;
lvPO.DataBind();
con.Close();
}

目前看起来是这样的

enter image description here

我想这样显示

enter image description here

最佳答案

你可以尝试使用select DISTINCT

cmd.CommandText = "SELECT DISTINCT Supplier.SupplierName, PurchaseOrder.PONo, PurchaseOrder.PODate, " +
"PurchaseOrder.PODateReceived, PurchaseOrder.PODeliveryDate, " +
"FROM PurchaseOrder INNER JOIN PurchaseOrderDetails " +
"ON PurchaseOrder.PONo = PurchaseOrderDetails.PONo INNER JOIN Supplier ON " +
"PurchaseOrder.SupplierNo = Supplier.SupplierID " +
"ORDER BY PurchaseOrder.PODate DESC";

或者尝试使用 GROUP BY

cmd.CommandText = "SELECT Supplier.SupplierName, PurchaseOrder.PONo, PurchaseOrder.PODate, " +
"PurchaseOrder.PODateReceived, PurchaseOrder.PODeliveryDate, " +
"FROM PurchaseOrder INNER JOIN PurchaseOrderDetails " +
"ON PurchaseOrder.PONo = PurchaseOrderDetails.PONo INNER JOIN Supplier ON " +
"PurchaseOrder.SupplierNo = Supplier.SupplierID " +
"GROUP BY PurchaseOrder.PONo,Supplier.SupplierName, PurchaseOrder.PODateReceived, PurchaseOrder.PODeliveryDate ORDER BY PurchaseOrder.PODate DESC";

关于c# - 选择事务,只显示一行,但在数据库中有多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com