gpt4 book ai didi

c# - 如何从数据行数组中删除数据行?

转载 作者:太空宇宙 更新时间:2023-11-03 23:22:49 24 4
gpt4 key购买 nike

我正在遍历一组数据行,当某个特定的随机项无效时,我想删除该项并获取新的总数以获取另一个随机项。但是当我删除数据行时,数据行不会消失......是的,可能有更好的方法来做到这一点,但我不够聪明,无法做到这一点......

我没有删除行,而是在里面看到了

ItemArray = podLps[1].ItemArray 引发了类型为 System.Data.RowNotInTableException 的异常

//PHASE 1: Get all LPs in the pod and add to collection
List<DataRow> allLps = dtLp.AsEnumerable().ToList();
DataRow[] podLps = allLps.Where(x => x.ItemArray[0].ToString() == loPod).ToArray();

//PHASE 2: Pick a random LP from collection that has valid WAVE1
for (int i = podLps.Count(); i > 0; i--)
{
//Recount items in collection since one may have been removed
int randomIndex = random.Next(podLps.Count());
var randomLpUserId = podLps[randomIndex].ItemArray[1].ToString();
var randomLpWave1 = int.Parse(podLps[randomIndex].ItemArray[2].ToString());

//Get WAVE1 # for selected LP
lpNumberOfLoans = GetNumberOfLoans(session, randomLpUserId);

//check if LP has valid WAVE1 then use this person
if (randomLpWave1 > lpNumberOfLoans)
{
return randomLpUserId;
}
else
{
podLps[randomIndex].Delete();
}
}

最佳答案

看看这个例子,它应该为您指明删除行的正确方向我刚刚测试过它并且它有效

for (int i = myDataTable.Rows.Count - 1; i >= 0; i--)
{
DataRow row = myDataTable.Rows[i]; //Remove
if (myDataTable.Rows[i][0].ToString() == string.Empty)
{
myDataTable.Rows.Remove(row);
}
}

关于c# - 如何从数据行数组中删除数据行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com