public bool yanzheng(string id, string pwd, string logintype)
{
bool b = false;
conn();//打开数据连接
if(logintype=="管理员")
{
string sql1 = string.Format("select count(*) from admin wherer loginid='{0}'", id);
cmd = new SqlCommand(sql1, con);
int num = 0;
num = (int)cmd.ExecuteScalar();//用户名数量
if (num == 1)
{
string sql = string.Format("select '{0}'from admin where loginid='{1}'", pwd, id);
SqlCommand cmd1 = new SqlCommand(sql, con);
read = cmd1.ExecuteReader();
while (read.Read())
{
string s = (string)read["loginpwd"];
if (s == pwd)
{
b= true;
return b;//1号位置
}
else
{
MessageBox.Show("密码错误", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
b=false;
return b;//2号位置
}
}
return b;//3号位置
}
else
{
MessageBox.Show("用户名不存在", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
b= false;
return b;//4号位置
}
return b;//5号位置
}
//下面还有一样的结构判断别的登录类型
如t 不管我在那个位置加return的值 都显示
错误
“MySchool.Db.yanzheng(string, string, string)”: 并非所有的代码路径都返回值
{
bool b = false;
conn();//打开数据连接
if(logintype=="管理员")
{
string sql1 = string.Format("select count(*) from admin wherer loginid='{0}'", id);
cmd = new SqlCommand(sql1, con);
int num = 0;
num = (int)cmd.ExecuteScalar();//用户名数量
if (num == 1)
{
string sql = string.Format("select '{0}'from admin where loginid='{1}'", pwd, id);
SqlCommand cmd1 = new SqlCommand(sql, con);
read = cmd1.ExecuteReader();
while (read.Read())
{
string s = (string)read["loginpwd"];
if (s == pwd)
{
b= true;
return b;//1号位置
}
else
{
MessageBox.Show("密码错误", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
b=false;
return b;//2号位置
}
}
return b;//3号位置
}
else
{
MessageBox.Show("用户名不存在", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
b= false;
return b;//4号位置
}
return b;//5号位置
}
//下面还有一样的结构判断别的登录类型
如t 不管我在那个位置加return的值 都显示
错误
“MySchool.Db.yanzheng(string, string, string)”: 并非所有的代码路径都返回值
{
bool b = false;
只有方法有返回值
一定要在最后return;
你看看你是不是最后一行没有这句话
retrun b;
}
那么else呢??
retrun b;
else和if 的结构一样 不过都是在5号位置返回的。。
只有这个if我把5个位置都写了
而不是直接return b;
如:
public bool yanzheng(string id, string pwd, string logintype)
{
bool b = false;
.........
return b;
}