private string login()
{
if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "")
{
MessageBox.Show("請檢查后重新輸入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return "-1";
}
if (comboBox1.Text == "學生")
{
string sql = "select * from Students where Name = '" + textBox1.Text + "'and PassWord = '" + textBox2.Text + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if (dr.Read())
{
return "學生";
}
else
{
return "-1";
}
}
if (comboBox1.Text == "老師")
{
string sql = "select * from Teachers where Name = '" + textBox1.Text + "'and PassWord = '" + textBox2.Text + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if (dr.Read())
{
return "老師";
}
else
{
return "-1";
}
if (comboBox1.Text == "管理員")
{
if (textBox1.Text == "admiin" && textBox2.Text == "admin")
{
return "管理員";
}
else
{
return "-1";
}
}
return "-1";
}
}
在做簡易的學生資訊管理系統的時候出現這樣的錯誤提示,有哪位大佬可以幫忙解答一下嗎?
uj5u.com熱心網友回復:
檢查下你最外層的if,如果(comboBox1.Text不等于學生也不等于老師,那它回傳什么uj5u.com熱心網友回復:
少了一個return值uj5u.com熱心網友回復:
private string login()
{
//if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "")
//{
// MessageBox.Show("請檢查后重新輸入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return "-1";
//}
if (comboBox1.Text == "學生")
{
string sql = "select * from Students where Name = '" + textBox1.Text + "'and PassWord = '" + textBox2.Text + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if (dr.Read())
{
return "學生";
}
else
{
return "-1";
}
}
if (comboBox1.Text == "老師")
{
string sql = "select * from Teachers where Name = '" + textBox1.Text + "'and PassWord = '" + textBox2.Text + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if (dr.Read())
{
return "老師";
}
else
{
return "-1";
}
if (comboBox1.Text == "管理員")
{
if (textBox1.Text == "admiin" && textBox2.Text == "admin")
{
return "管理員";
}
else
{
return "-1";
}
}
return "-1";
}
MessageBox.Show("請檢查后重新輸入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return "-1";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/251061.html
標籤:C#
上一篇:目前大多企業使用的sqlserver資料庫是哪個版本?
下一篇:求助替換
