System.collections.generic.ienumerable<system.data.datarow> copytodatatable()


#1

hi all, is there anyway to count rows of a variable whose type is system.collections.generic.ienumerable<system.data.datarow>?, i use copytodatatable() to convert it to datatable and want to write range in an excel, but since there is no qualified rows, it shows an error:Write line : The source contains no DataRows. how to solve this? i then use if to put condition like"exception.copytodatatable() is nothing", it still shows this error, could sb share some solution? many thanks.


#2

Assuming your ienumerable name is “enum”

You can use enum.Count()//int or enum.Any()//boolean

For datatable - dt.Rows.Count( tostring in messagebox)


#3

thanks,it works