DataTable.Select() Property: Giving Index Out of Bound Exception

asp.net, c#

Solution

`DataTable.Select` does not return `null` when there's no matching `DataRow` but an array with `Length==0`.

But apart from that, why are you using an "infinite" loop for only one statement?

So this should work:

drPar = dt.Select("MenuID=" + predecessor);
if (drPar.Length != 0)
{
    if (drPar[0]["ParentID"].ToString().Equals("0"))
    {
       // ...
    }
}

Problem

I'm trying to select only those rows which have Parent ID = 0 ``` int predecessor = Parent; StringBuilder valuePath = new StringBuilder(); valuePath.Append(Parent.ToString()); DataRow[] drPar; while (true) { drPar = dt.Select("MenuID=" + predecessor); if (drPar != null) { if (drPar[0]["ParentID"].ToString().Equals("0")) break; } ``` drPar[0]["ParentID"].ToString().Equals("0") is giving me Out of Bound exception .. Help Please !

Original source