类,结构或借口成员声明中的标记"else"无效,求大神指点!
privatevoidbutton1_Click(objectsender,EventArgse){if(checkBox1.Checked==true){连数据库的代码...
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
连数据库的代码,跟下面的除了表名都一样
}
else if (checkBox2.Checked == true) //此处"else" 无效,"=="无效
{string uname = this.textBox1.Text.ToString();
string upassword = this.textBox2.Text.ToString();
SqlConnection thisconnection = new SqlConnection(@"Server=服务器名;Integrated Security=True;" + "DataBase=学生信息");
thisconnection.Open(); //此处"("无效
SqlCommand thiscommand = thisconnection.CreateCommand();
thiscommand.CommandText = "select 学号,密码 from 学生登录 where 学号='" + uname + " '";
SqlDataReader thisreader = thiscommand.ExecuteReader();
if (thisreader.Read())
{
if (thisreader["密码"].ToString().Trim() == upassword)
{
MessageBox.Show("恭喜您登陆成功!", "登陆成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Visible = false;
new Form5().Show();
}
else //无效
{
this.textBox2.Text = "";
MessageBox.Show("密码错误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
thisconnection.Close();
thisreader.Close();
} 展开
{
if (checkBox1.Checked == true)
{
连数据库的代码,跟下面的除了表名都一样
}
else if (checkBox2.Checked == true) //此处"else" 无效,"=="无效
{string uname = this.textBox1.Text.ToString();
string upassword = this.textBox2.Text.ToString();
SqlConnection thisconnection = new SqlConnection(@"Server=服务器名;Integrated Security=True;" + "DataBase=学生信息");
thisconnection.Open(); //此处"("无效
SqlCommand thiscommand = thisconnection.CreateCommand();
thiscommand.CommandText = "select 学号,密码 from 学生登录 where 学号='" + uname + " '";
SqlDataReader thisreader = thiscommand.ExecuteReader();
if (thisreader.Read())
{
if (thisreader["密码"].ToString().Trim() == upassword)
{
MessageBox.Show("恭喜您登陆成功!", "登陆成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Visible = false;
new Form5().Show();
}
else //无效
{
this.textBox2.Text = "";
MessageBox.Show("密码错误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
thisconnection.Close();
thisreader.Close();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询