Min (5) must be less than or equal to max (-1) in a Range object?
Asked Answered
R

1

11

I am getting the error in the inner foreach while using Select in datatable.

Here is the code I tried so far

foreach (DataRow drOuter in dtLogic.Select("Name='>' OR Name='='"))
{
     foreach (DataRow drInner in dtLogic.Select("ParentId=" + Convert.ToInt64(drOuter["Id"]) + ""))
     {  

     }
}

where Convert.ToInt64(drOuter["Id"]) have the value 2107362180 when I checked in Immediate Window.
Then why does it throw the below error?

enter image description here

Raiment answered 5/1, 2015 at 11:28 Comment(0)
F
18

You should check for strings and not for numbers so insert single quotes in query expr='string'

foreach (DataRow drInner in dtLogic.Select("ParentId='" + Convert.ToInt64(drOuter["Id"]) + "'"))
{  

}

after this edit you can replace as @Christos answer says

Convert.ToInt64(drOuter["Id"])

with

drOuter["Id"].ToString()
Floret answered 5/1, 2015 at 11:38 Comment(1)
Yes. I had missed single quotes inside datatable.Select(). Since the column contains only int values, still Convert.ToInt64(drOuter["Id"]) is working. Thanks a lot @FloretRaiment

© 2022 - 2024 — McMap. All rights reserved.