Without looking at the data returned from your database, I can only assume that the following part of your LINQ is to blame:
x.Field<Int32>("userid")
Your userid column value is probably not int, would I put my money on it as NULL?
UPDATE . Can you confirm that this is not a field challenge that breaks? Just change your code to something like this without a field call:
public int getCount(int usercode){ int count = 0; DataTable mytable = getAllRowsAndReturnAsDataTable();
You can also check which values ββare returned by mytable.AsEnumerable () in the viewport, for example, to make sure everything looks right. If the above code works, then it initiates a field call. Find out which line cannot be passed to and from Int32.
If it is really NULL, there are several ways to solve this problem.
source share