Why does this code block say "not all code paths return a value"?
- by Kishan
I wrote following code...but i am getting Error like:
Error 1 'LoginDLL.Class1.Login(string, string, string)': not all code paths return a value
Please help me...
Thanks in advance...
My code is as given below...
public int Login(string connectionString,string username,string password)
{
SqlConnection con=new SqlConnection(connectionString);
con.Open();
SqlCommand validUser = new SqlCommand("SELECT count(*) from USER where username=@username", con);
validUser.Parameters.AddWithValue("@username", username);
int value=Convert.ToInt32(validUser.ExecuteScalar().ToString());
if (value == 1)
{
//check for password
SqlCommand validPassword = new SqlCommand("SELECT password from USER where username=@username", con);
validPassword.Parameters.AddWithValue("@username", username);
string pass = validPassword.ExecuteScalar().ToString();
if (pass == password)
{
//valid login
return 1;
}
else
{
return 0;
}
}
else if (value == 0)
{
return 2;
}
}