long
is Int64
in .NET; it is just an alias in C#. Your problem is casting the return value to long
and unless we know the type coming back from your query for sure, we would not know why you get an error. SQL BigInt must be convertable to long
.
If it is the COUNT(*) which is coming back, then it is Int32. You need to use the Convert
class:
long l = Convert.ToInt64(selectCommand.ExecuteScalar());