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 !
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"))
    {
       // ...
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With