B
Bungle
Hi
I am trying to do something really simple. Create a method within a
class which will connect to the database, pull back a result and
return it out the method. Not hard.
All my database connections and executescalar work fine, but, I want
to put it into a Try Catch statement so that if a problem occurs, it
will error out to my error page.
How can I do all this and return a value within the Try Catch???
public int getUserIdByUsernamePassword(String username, String
userPassword)
{
try
{
databaseConnect.Open();
int userId;
cmdGetUserDetailsByUsernamePassword.Parameters["@username"].Value =
username;
cmdGetUserDetailsByUsernamePassword.Parameters["@userPassword"].Value
= userPassword;
userId = (int)cmdGetUserDetailsByUsernamePassword.ExecuteScalar();
return userId
}
catch
{
// Error page call.
}
}
The method does not recognise the fact that I have a returned a value.
Hopefully someone can give me an explanation how I can still have the
benefits of a Try Catch statement while still being able to return a
value out of the method.
Thank you very much
I am trying to do something really simple. Create a method within a
class which will connect to the database, pull back a result and
return it out the method. Not hard.
All my database connections and executescalar work fine, but, I want
to put it into a Try Catch statement so that if a problem occurs, it
will error out to my error page.
How can I do all this and return a value within the Try Catch???
public int getUserIdByUsernamePassword(String username, String
userPassword)
{
try
{
databaseConnect.Open();
int userId;
cmdGetUserDetailsByUsernamePassword.Parameters["@username"].Value =
username;
cmdGetUserDetailsByUsernamePassword.Parameters["@userPassword"].Value
= userPassword;
userId = (int)cmdGetUserDetailsByUsernamePassword.ExecuteScalar();
return userId
}
catch
{
// Error page call.
}
}
The method does not recognise the fact that I have a returned a value.
Hopefully someone can give me an explanation how I can still have the
benefits of a Try Catch statement while still being able to return a
value out of the method.
Thank you very much