G
Guest
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.)
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.)