C#如何将列表中的一个值仅返回到ComBox中?而不是全部
我的目标是将C#如何将列表中的一个值仅返回到ComBox中?而不是全部,c#,C#,我的目标是将CustomerName的单个值返回到组合框中 这是我从数据库获取数据的方式: public class DataAccess { public List<ComplaintModel> FindOrderNumber(string orderNumber) { using(SqlConnection conn = new SqlConnection(ConnectionString.MJMconnString)) {
CustomerName
的单个值返回到组合框中
这是我从数据库获取数据的方式:
public class DataAccess
{
public List<ComplaintModel> FindOrderNumber(string orderNumber)
{
using(SqlConnection conn = new SqlConnection(ConnectionString.MJMconnString))
{
var output = conn.Query<ComplaintModel>($@"
SELECT
TRIM(p.description) as Product,
c.name AS CustomerName,
FROM SalesOrder so JOIN SalesOrderLine sol ON
so.id = sol.salesOrderID JOIN Customer c ON
so.customerID = c.id JOIN Product p ON
sol.productID = p.id WHERE so.number = '{orderNumber}'").ToList();
return output;
}
}
}
组合框的所需输出
这是我的型号
public class ComplaintModel
{
public string CustomerName { get; set; }
public string Product { get; set; }
}
问题
如何在组合框中仅检索CustomerName
的单个值?您需要创建:
客户类别,
订单类
然后需要为两个组合框创建两个列表:
列出客户
用于客户组合框
列出订单
for orders组合框显示所选客户的订单(在组合框更改事件中)
公共类客户
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
公共列表顺序{get;set;}
}
公共阶级秩序
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
public int CustomerId{get;set;}
}
您需要创建:
客户类别,
订单类
然后需要为两个组合框创建两个列表:
列出客户
用于客户组合框
列出订单
for orders组合框显示所选客户的订单(在组合框更改事件中)
公共类客户
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
公共列表顺序{get;set;}
}
公共阶级秩序
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
public int CustomerId{get;set;}
}
如果只有一个值,则组合框不是最适合的控件。您可以在标签中显示客户的姓名。对于您的问题,您只能在数据源中添加一个元素,如customer\u name.DataSource=new[]{OrderNumber[0]}代码>。如果只有一个值,则组合框不是最适合的控件。您可以在标签中显示客户的姓名。对于您的问题,您只能在数据源中添加一个元素,如customer\u name.DataSource=new[]{OrderNumber[0]}代码>。
public class ComplaintModel
{
public string CustomerName { get; set; }
public string Product { get; set; }
}
public class Customer
{
public string Id {get;set;}
public string Name {get;set;}
public List<Order> Orders {get;set;}
}
public class Order
{
public string Id {get;set;}
public string Name {get;set;}
public int CustomerId {get;set;}
}