Re: Help with ExecuteScalar
If the table exists and it's a valid field name, how can it not return a value? (btw, ID should be in [] as it's a reserved word).
If you want to check if it has a value, use a simple if/then/else and return what you would preffer as a default. Or, in the transact statement, use:
"Select isnull(Max([id]), 0) from users"
Change the 0 to whatever default value you want to return.
Re: Help with ExecuteScalar
Code:
object result = sqlCmd.ExecuteScalar();
if (result is int)
{
// The query returned an integer value.
}
Re: Help with ExecuteScalar
Quote:
If the table exists and it's a valid field name, how can it not return a value?
users table and field name exist and they both have valid name, is just that i dont have any rows from my users tables
Code:
object result = sqlCmd.ExecuteScalar();
if (result is int)
{
// The query returned an integer value.
}
Since I assigned the return value to result which is in type object how can i convert it to int type? i already tried the but it won't work.