问题描述
我有一个数据表,如
DataTable dt1 = new DataTable();
dt1。 Columns.AddRange(new DataColumn [2] {new DataColumn(Name),new DataColumn(PriceFrom)});
dt1.Rows.Add(ABCD EGFHR,345.33 );
dt1.Rows.Add(KUGHJ SHDGYN,212.44);
dt1.Rows.Add(QAFRDGDJFK,564.22);
DataTable dt2 = new DataTable();
dt2.Columns.AddRange(new DataColumn [2] {new DataColumn(Name),new DataColumn(PriceFrom)});
dt2.Rows.Add(EGFHR,222.22);
dt2.Rows.Add(QAFRDGDJFK,456.33);
dt2.Rows.Add(KUGHJ,214.44);
我使用了
I have a datatable like
DataTable dt1 = new DataTable();
dt1.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"),new DataColumn("PriceFrom") });
dt1.Rows.Add("ABCD EGFHR","345.33");
dt1.Rows.Add("KUGHJ SHDGYN","212.44");
dt1.Rows.Add("QAFRDGDJFK","564.22");
DataTable dt2 = new DataTable();
dt2.Columns.AddRange(new DataColumn[2]{ new DataColumn("Name"),new DataColumn("PriceFrom") });
dt2.Rows.Add("EGFHR","222.22");
dt2.Rows.Add("QAFRDGDJFK","456.33");
dt2.Rows.Add("KUGHJ ","214.44");
I have used
var query = from dt1Row in dt1.AsEnumerable()
join dt2Row in dt2.AsEnumerable() on 1 equals 1
where dt1Row.Field<string>("Name").IndexOf(dt2Row.Field<string>("UserId")) != -1
select new
{
Name = dt1Row.Field<string>("Name"),
MinPrice = Convert.ToDouble(dt1Row.Field<string>("PriceFrom")) > Convert.ToDouble(dt2Row.Field<string>("PriceFrom")) ? dt2Row.Field<string>("PriceFrom") : dt1Row.Field<string>("PriceFrom")
};
这是正确的..但在此,我也想从datatable1添加不在第二个数据表中的值,反之亦然..
我希望你明白
问候
maulik shah
this is correct..but in this , i also want to add values from datatable1 that are not in second datatable and vice versa ..
i hope u understood
regards
maulik shah
推荐答案
这篇关于一个数据表列值LIKE在其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!