我有一个使用DataBase数据创建的列表。 列表中的结构是:
public struct GetInfoForGraph
{
public float A { get; set; }
public float B { get; set; }
public DateTime Time { get; set; }
public String Customer_name { get; set; }
public String Type_name { get; set; }
public String Program_name { get; set; }
public int Id_Tbl_Program { get; set; }
public int Id_Tbl_File_Names { get; set; }
public string File_Name { get; set; }
}
我在列表中添加数据如下:
public List<GetInfoForGraph> CreatesListInfoForGraphPoints()
{
string sqlCommand = "SELECT A AS A";
sqlCommand += ", B AS B";
sqlCommand += ", TIME_FORMATTED AS Time";
sqlCommand += ", CUSTOMER_NAME As Customer_name";
sqlCommand += ", PROGRAM_NAME As Program_name";
sqlCommand += ", TYPE_NAME As Type_name";
sqlCommand += ", ID_TBL_PROGRAM AS Id_Tbl_Program";
sqlCommand += ", ID_TBL_FILE_NAMES as Id_Tbl_File_Names";
sqlCommand += ", ONLY_FILE_NAME as File_Name";
sqlCommand += " FROM VW_MAIN_INFO";
sqlCommand += " where CUSTOMER_NAME = '" + Project.CustomerName + "'";
sqlCommand += " and PROGRAM_NAME = '" + Project.ProgramName + "'";
sqlCommand += " and TYPE_NAME = '" + Project.TypeName + "'";
sqlCommand += " ORDER BY Time";
List<GetInfoForGraph> DataForGraph = new List<GetInfoForGraph>();
SqlConnection conn = new SqlConnection(@"XXXX");
SqlCommand cmd = new SqlCommand(sqlCommand, conn);
SqlDataReader dr;
try
{
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
DataForGraph.Add(new GetInfoForGraph()
{
A = dr.GetFloat(dr.GetOrdinal("A")),
B = dr.GetFloat(dr.GetOrdinal("B")),
Time = dr.GetDateTime(dr.GetOrdinal("Time")),
Customer_name = dr.GetString(dr.GetOrdinal("Customer_name")),
Program_name = dr.GetString(dr.GetOrdinal("Program_name")),
Type_name = dr.GetString(dr.GetOrdinal("Type_name")),
Id_Tbl_Program = dr.GetInt32(dr.GetOrdinal("Id_Tbl_Program")),
Id_Tbl_File_Names = dr.GetInt32(dr.GetOrdinal("Id_Tbl_File_Names")),
File_Name = dr.GetString(dr.GetOrdinal("File_Name"))
});
}
dr.Close();
}
catch (Exception ex)
{
ActivityLog.LogError(new StackTrace(true), ex);
}
finally
{
conn.Close();
}
return DataForGraph;
} // End of List<GetInfoForGraph> CreatesListInfoForGraphPoints()
我想补充一下我的&#34; DropDown&#34;事件以下信息:
我尝试了什么: *来自Here的想法
private void CboxReceiveNameFile_DropDown(object sender, EventArgs e)
{
List<int> result = DataForGraph.Select(o => o.FirstInteger).Distinct().ToList();
}
但它给了我错误&#39;对象&#39;不包含选择和无扩展方法的定义&#39;选择&#39;接受类型&#39;对象&#39; ...
的第一个参数有什么身体可以帮助我吗?欢迎任何帮助!谢谢