Error Message: Specified cast is not valid.
tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0);
Based on the error, it is pretty clear that the type cast you tried to do is not valid. This means,
of datatype integer.
Make sure, you have column named as 'childnodecount' in your dataset and then do make sure it is having an integer value before casting it directly into an int. Once you are sure of all, try:
tn.PopulateOnDemand = (Convert.ToInt32(dr["childnodecount"]) > 0);