我写下面的代码...但我收到错误,如:为什么这段代码会说“不是所有的代码路径都返回一个值”?
错误1“LoginDLL.Class1.Login(字符串,字符串,字符串)”:不是所有的代码路径返回一个值
请帮我...提前
谢谢...作为如下
我的代码...
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 [email protected]", 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 [email protected]", 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;
}
}
作为额外的注意事项确保使用'使用',所以你正确地处理/关闭连接。 U可以在SqlConnection和SqlCommand上使用。那么当你完成这些任务时,你不必使用.Close()。 – MadBoy 2010-03-20 20:32:57