private void bttupdate_Click(object sender, EventArgs e)
        {
            if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd.Text.Trim() == "")
            {
                MessageBox.Show("填入修改完整信息", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            } 
            UserInfo userInfo = new UserInfo();
            userInfo.Name = textName.Text;
            userInfo.Age = textAge.Text;
            userInfo.Address = textAddress.Text;
            userInfo.Pwd = textPwd.Text;
            UserBLL ub = new UserBLL();
            else if(ub.updateUser(userInfo))
            {
                MessageBox.Show("修改成功","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("修改失败", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }            textName.Clear();
            textAge.Clear();
            textAddress.Clear();
            textPwd.Clear();            this.Close();
        }红色的字体说  无效的表达式项“else” 说 "if"应输入;

解决方案 »

  1.   

    private void bttupdate_Click(object sender, EventArgs e)
     {
      if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd.Text.Trim() == "")
        {
         MessageBox.Show("填入修改完整信息", "操作提示",      MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
        }  
         UserInfo userInfo = new UserInfo();
         userInfo.Name = textName.Text;
         userInfo.Age = textAge.Text;
         userInfo.Address = textAddress.Text;
         userInfo.Pwd = textPwd.Text;
         UserBLL ub = new UserBLL();
      if(ub.updateUser(userInfo))
      {
      MessageBox.Show("修改成功","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
      }
      else
      {
      MessageBox.Show("修改失败", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
      }  textName.Clear();
      textAge.Clear();
      textAddress.Clear();
      textPwd.Clear();  this.Close();
      }
      

  2.   

    把你报错地方的else去掉就好了
      

  3.   

     UserInfo userInfo = new UserInfo();
      userInfo.Name = textName.Text;
      userInfo.Age = textAge.Text;
      userInfo.Address = textAddress.Text;
      userInfo.Pwd = textPwd.Text;
      UserBLL ub = new UserBLL();
     晕哦···第一次见到你这种写法哦··
    就是把else 去掉··或者你把代码放在判断里面
      

  4.   

    private void bttupdate_Click(object sender, EventArgs e)
      {UserInfo userInfo = new UserInfo();
      userInfo.Name = textName.Text;
      userInfo.Age = textAge.Text;
      userInfo.Address = textAddress.Text;
      userInfo.Pwd = textPwd.Text;
      UserBLL ub = new UserBLL();  if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd.Text.Trim() == "")
      {
      MessageBox.Show("填入修改完整信息", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
      }  
      
      else if(ub.updateUser(userInfo))
      {
      MessageBox.Show("修改成功","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
      }
      else
      {
      MessageBox.Show("修改失败", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
      }  textName.Clear();
      textAge.Clear();
      textAddress.Clear();
      textPwd.Clear();  this.Close();
      }既然要使用这种结构,代码就得在if(){}  eleseif(){}  else(){}这里面
      

  5.   

     if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd
    楼主你用的或者,应该用并且&&
     if (textName.Text.Trim() == ""&& textAge.Text.Trim() == "" && textAddress.Text.Trim() == "" && textPwd你那样有一个不为空程序就走了
      

  6.   


    private void bttupdate_Click(object sender, EventArgs e)
      {
      if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd.Text.Trim() == "")
      {
      MessageBox.Show("填入修改完整信息", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
       return;//这里lz肯定是要跳出这个事件不往下执行的
      }  
      UserInfo userInfo = new UserInfo();
      userInfo.Name = textName.Text;
      userInfo.Age = textAge.Text;
      userInfo.Address = textAddress.Text;
      userInfo.Pwd = textPwd.Text;
      UserBLL ub = new UserBLL();
      if(ub.updateUser(userInfo))//这里不知道要else干嘛呢,都不匹配哒.你不是认为是和上面的if匹配的吧
      {
      MessageBox.Show("修改成功","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
      }
      else
      {
      MessageBox.Show("修改失败", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
      }  textName.Clear();
      textAge.Clear();
      textAddress.Clear();
      textPwd.Clear();  this.Close();
      }
      

  7.   

    都错了 是不应该在if{}后面写
      UserInfo userInfo = new UserInfo();
      userInfo.Name = textName.Text;
      userInfo.Age = textAge.Text;
      userInfo.Address = textAddress.Text;
      userInfo.Pwd = textPwd.Text;
      UserBLL ub = new UserBLL();
      

  8.   

    9楼正解  或者private void bttupdate_Click(object sender, EventArgs e)
      {
      if (textName.Text.Trim() == "" || textAge.Text.Trim() == "" || textAddress.Text.Trim() == "" || textPwd.Text.Trim() == "")
      {
      MessageBox.Show("填入修改完整信息", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);  }else{  
      UserInfo userInfo = new UserInfo();
      userInfo.Name = textName.Text;
      userInfo.Age = textAge.Text;
      userInfo.Address = textAddress.Text;
      userInfo.Pwd = textPwd.Text;
      UserBLL ub = new UserBLL();
      if(ub.updateUser(userInfo))//这里不知道要else干嘛呢,都不匹配哒.你不是认为是和上面的if匹配的吧
      {
      MessageBox.Show("修改成功","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
      }
      else
      {
      MessageBox.Show("修改失败", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
      }  textName.Clear();
      textAge.Clear();
      textAddress.Clear();
      textPwd.Clear();  this.Close();
      }
    }
      

  9.   

    建议 单例  UserBLL