c# dataset内定位某个格的值

来源:百度知道 编辑:UC知道 时间:2024/05/20 17:22:04
dataset.Tables["RoomType"]
form:
TypeName Price
标间 60
套间 800
豪华间 260

我现在想根据TypeName"标间"在表中搜索得到相对应的Price"60"
该怎么写?

String price=dataset.Tables["RoomType"].Rows[行的索引]["Price "].ToString();
直接这样就取出来了!

string sql=“select * from roomtype where typename='"+typename+"'”
然后填充dataset
取值:
string price=dataset.Table[0].Rows[0]["price"].ToString();
这样就行了。。。

还有可以用一个循环
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if(GridView1.Rows[i].Cells[2]==6)
{
.....
}
}

.Net 3.5
dataset.Tables["RoomType"].AsEnumerable().Where(r=>r.Field<string>("TypeName") == "标间"&& r.Field<decimal>("Price")==60).CopyToDataTable();
或者
dataset.Tables["RoomType"].Select("[TypeName] = '标间' AND [Price] = 60").CopyToDataTable();