Why does this code block say "not all code paths return a value"?

Posted by Kishan on Stack Overflow See other posts from Stack Overflow or by Kishan
Published on 2010-03-20T20:21:43Z Indexed on 2010/03/20 20:31 UTC
Read the original article Hit count: 274

Filed under:
|

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;

    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET