我需要从列表中选择特定的两列,并为两个组合框加载这些值.我试图使用LINQ这样做,它传递给我一个错误"无法将类型的对象强制转换为'类型'System.Collections.Generic.List".
这是我的方法,
private void getVehicleNo()
{
List<Exp_VehicleDTO> oData = oVehicleBL.VehiclesSearch(Convert.ToInt32(Session["CompanyID"].ToString()));
oData = ((List<Exp_VehicleDTO>)oData.SelectMany(x => x.VehicleNo)).ToList();
ddVehicleNo.DataSource = oData;
ddVehicleNo.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
这是车辆搜索方法,
public List<Exp_VehicleDTO> VehiclesSearch(int companyId)
{
List<Exp_VehicleDTO> results = new List<Exp_VehicleDTO>();
try
{
using (CloudConnection oCloudConnection = new CloudConnection(DMSSWE.Common.ConnectionString))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" SELECT ");
sb.AppendLine("CompanyID,");
sb.AppendLine("VehicleId,");
sb.AppendLine("VehicleType,");
sb.AppendLine("VehicleNo,");
sb.AppendLine("Status,");
sb.AppendLine("CreatedDateTime,");
sb.AppendLine("CreatedBy,");
sb.AppendLine("CreatedMachine ");
sb.AppendLine(" FROM Exp_CompanyVehicle ");
sb.AppendLine(" WHERE 1=1 ");
sb.AppendLine(" AND (CompanyID=?CompanyID)");
oCloudConnection.CommandText = sb.ToString();
oCloudConnection.Parameters.Clear();
oCloudConnection.Parameters.Add(new Parameter { Name = "CompanyID", Value = …Run Code Online (Sandbox Code Playgroud)