for(每个)在遍历所有列表之前结束

时间:2019-02-16 13:14:55

标签: c# database for-loop foreach

我也尝试使用for代替foreach(当然更改()的内部),但仍然无法正常工作。我能做什么? tableSiblings已初始化

运行代码时,它只会遍历tableSiblings.Rows中一小部分的行,而不是全部

enter codsSiblings = dal.GetDataSet("Select * From Siblings");
// Go through the table:
foreach (DataGridViewRow row in tableSiblings.Rows)
{
    // If this is a new row:
    if ((row.Cells["siblingID"].Value ?? string.Empty).ToString() == string.Empty.ToString())
    {
        DoSomething();
    }
    else
    {
        // Go through the database:
        foreach (DataRow dr in dsSiblings.Tables[0].Rows)
        {
            // If a sibling with the same ID exists:
            if ((row.Cells["siblingID"].Value ?? string.Empty).ToString() == dr["siblingID"].ToString())
            {
                DoSomethingElse();
                break;
            }
        }
    }
}
dal.UpdateDataSet(dsSiblings);

0 个答案:

没有答案