I know this one is basic (and Thanks)
i have a function that calls a storedprocedure and i'm using the return
code for validation See Below
public Boolean fn_isVaildUser(string userid, string password)
{
// returns 0 invalid or 1 valid for a userid and password
string constr =
ConfigurationManager.ConnectionStrings["arlcapConnectionString"].ConnectionString;
SqlConnection sqlcon1 = new SqlConnection(constr);
SqlCommand sqlcmd1 = sqlcon1.CreateCommand();
sqlcmd1.CommandType = CommandType.StoredProcedure;
sqlcmd1.CommandText = "sp_GetUserLogin";
sqlcmd1.Parameters.AddWithValue("@szUserid", userid);
sqlcmd1.Parameters.AddWithValue("@szPassword", password);
SqlParameter isOK = sqlcmd1.Parameters.Add("@isOK", null);
isOK.SqlDbType = SqlDbType.Int;
isOK.Direction = ParameterDirection.ReturnValue;
sqlcon1.Open();
sqlcmd1.ExecuteNonQuery();
sqlcon1.Close();
sqlcmd1.Dispose();
sqlcon1 = null;
sqlcmd1 = null;
if ((Int32)isOK.Value == 0)
return false;
else
return true;
/// return (Boolean)isOK.Value;
}
The question has to do with the last commented out line.
I want to just want t ocast and return the "isOK.Value but i keep getting
errors.
ERROR: "Specified cast is not valid."
(It does work as is, but i'd perfer to do it what i consider correctly.)

Signature
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
Sherif Elmetainy - 27 Aug 2007 18:02 GMT
Your parameter type should be bit so that you can cast it to Boolean.
Otherwise you can use Convert.ToBoolean(isOK.Value)
Regards,
Sherif
>I know this one is basic (and Thanks)
> i have a function that calls a storedprocedure and i'm using the return
[quoted text clipped - 31 lines]
> ERROR: "Specified cast is not valid."
> (It does work as is, but i'd perfer to do it what i consider correctly.)
WebBuilder451 - 27 Aug 2007 19:12 GMT
Thank you,
I'm still getting used to C#, but i think in this case is was an issue of
missing the obvious!

Signature
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
> Your parameter type should be bit so that you can cast it to Boolean.
> Otherwise you can use Convert.ToBoolean(isOK.Value)
[quoted text clipped - 37 lines]
> > ERROR: "Specified cast is not valid."
> > (It does work as is, but i'd perfer to do it what i consider correctly.)