我的 C# 应用程序需要 2 个Datatables
。第一个表是从数据库中填充的。第二个表需要动态构建,因此它将第一个表中的每一行复制 3 次,并显示具有不同列名的列的子集。
到目前为止,我已经通过构建 3 个linq
查询然后连接结果来实现这一点。例如
var query1 = from result in MainDataTable.AsEnumerable()
select new
{
MyRowID = result.Field<string>("MyRowID"),
Type = "ABC",
ScheduleDate = result.Field<DateTime>("Date1")
};
var query2 = from result in MainDataTable.AsEnumerable()
select new
{
MyRowID = result.Field<string>("MyRowID"),
Type = "DEF",
ScheduleDate = result.Field<DateTime>("Date2")
};
var query3 = from result in MainDataTable.AsEnumerable()
select new
{
MyRowID = result.Field<string>("MyRowID"),
Type = "GHI",
ScheduleDate = result.Field<DateTime>("Date3")
};
var queryFinal = query1.Concat(query2).Concat(query3);
然后我将 queryFinal 设置为我的日历组件的数据源。
但是,在我再次运行上述代码之前,日历组件MainDataTable
中不存在对内容的任何更改。datasource
是否可以构建一个对象或查询,而不是复制,而是引用MainDataTable
数据并因此自动刷新?