从asp.net中的数据表中选择
问题描述:
好的..还有一个问题是,
我有onedatatable列是ruleid,descp
和在seconddatatable,我有列hotelid,ruleid
现在我想检查
如果secondtable.contains hotelid,选择ruleid,如果(onedatatable.contains ruleid from seconddatatable,选择descp in onedatatable)
i希望你明白..
ok..one other question is ,
I have onedatatable where column is ruleid,descp
and in seconddatatable, i have column hotelid,ruleid
now i want to check
if secondtable.contains hotelid,select ruleid and,if(onedatatable.contains ruleid from seconddatatable,select descp in onedatatable)
i hope u understood..
答
你可以使用Linq:
You can do it with Linq:
DataTable dtOne = new DataTable();
dtOne.Columns.Add("ruleid", typeof(int));
dtOne.Columns.Add("descp", typeof(string));
dtOne.Rows.Add(1, "hello");
dtOne.Rows.Add(2, "there");
dtOne.Rows.Add(3, "world");
DataTable dtTwo = new DataTable();
dtTwo.Columns.Add("hotelid", typeof(int));
dtTwo.Columns.Add("ruleid", typeof(int));
dtTwo.Rows.Add(1, 1);
dtTwo.Rows.Add(2, 1);
dtTwo.Rows.Add(3, 2);
dtTwo.Rows.Add(4, 3);
dtTwo.Rows.Add(5, 4);
var results = from rowOne in dtOne.AsEnumerable()
join rowTwo in dtTwo.AsEnumerable() on rowOne.Field<int>("ruleId") equals rowTwo.Field<int>("ruleid")
where rowTwo.Field<int>("hotelid") == 3
select new { hotelid = rowTwo["hotelid"], descp = rowOne["descp"] };
我用
results.SingleOrDefault()。amount.ToString( )获得金额......它已经解决了..
I use
results.SingleOrDefault().amount.ToString() to get amount ...it has solved..