Home > Net >  Error CS0161 "Form1. The login () :" not all code paths return values
Error CS0161 "Form1. The login () :" not all code paths return values

Time:01-22

Private string the login ()
{
If (textBox1. Text=="" | | textBox2. Text==" "| | comboBox1. Text==" ")
{
MessageBox. Show (" please check and enter again ", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Warning).
Return "1";
}
If (comboBox1. Text=="students")
{
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 "students";
}
The else
{
Return "1";
}

}
If (comboBox1. Text=="teacher")
{
String SQL="select * from head where Name='" + textBox1. Text +"' and PassWord='" + textBox2. Text + "' ";

Dao Dao=new Dao ();
IDataReader Dr=dao. Read (SQL);
If (Dr. Read ())
{
Return "teacher";
}
The else
{
Return "1";
}
If (comboBox1. Text=="administrator")
{
If (textBox1. Text=="admiin" & amp; & TextBox2. Text=="admin")
{
Return "administrator";
}
The else
{
Return "1";
}
}
Return "1";

}
}
When doing the simple student information management system appear such errors, which members can help solve?

CodePudding user response:

Check your the outermost layer of the if, if (comboBox1. The Text is not equal to students is not equal to the teacher, what it returns

CodePudding user response:

A return value

CodePudding user response:

 private string the login () 
{
//if (textBox1. Text=="" | | textBox2. Text==" "| | comboBox1. Text==" ")
//{
//MessageBox. Show (" please check and enter again ", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Warning).
//return "1";
//}
If (comboBox1. Text=="students")
{
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 "students";
}
The else
{
Return "1";
}

}
If (comboBox1. Text=="teacher")
{
String SQL="select * from head where Name='" + textBox1. Text +"' and PassWord='" + textBox2. Text + "' ";

Dao Dao=new Dao ();
IDataReader Dr=dao. Read (SQL);
If (Dr. Read ())
{
Return "teacher";
}
The else
{
Return "1";
}
If (comboBox1. Text=="administrator")
{
If (textBox1. Text=="admiin" & amp; & TextBox2. Text=="admin")
{
Return "administrator";
}
The else
{
Return "1";
}
}
Return "1";

}

MessageBox. Show (" please check and enter again ", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Warning).
Return "1";
}
  •  Tags:  
  • C#
  • Related