我正在通過一個foreach
循環的數據集循環嘗試刪除沒有與指定的值匹配的數組的行,並且我想要獲取ds
數據集中當前行的索引刪除該行。例如:如何獲取數據集中某行的索引?
for(int i =1;i<=TotalWinners;i++)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["ID"] != Winners[i, 0])
{
//int x = ds.Tables[0].Rows.IndexOf();
int index = ds.Tables[0].Rows.IndexOf[current row index]
}
}
}
如何獲得循環中該行的索引?如果我無法獲得該行的索引,那麼如何通過ID選擇並刪除該行?
@Ali,你可以這樣做ds.Tables [0] .Rows [i] [「ID」] – Adil