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"应输入;
{
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"应输入;
解决方案 »
- 一个简单的SQL语句谁帮谢谢哈
- 求帮助
- 用openfiledialog与savefiledialog之后的问题
- C#程序如何使用SQL Server2005的语句截取wendosXP系统的当前日期
- 问个关于MSMQ的问题
- C#如何判断客户端是否安装了Adobe Reader 软件啊?
- 简单问题送分:怎样在treeview中添加checkbox控件?
- 姐姐哥哥妹妹弟弟帮忙 不同网站共享Session问题
- 怎么判断一组数据是否服从正态分布啊?
- 语音播放多线程问题
- SQL截取字符串的问题
- 将string numStr = "1234.56789";分别转换为int ,float , double,并输出结果
{
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();
}
userInfo.Name = textName.Text;
userInfo.Age = textAge.Text;
userInfo.Address = textAddress.Text;
userInfo.Pwd = textPwd.Text;
UserBLL ub = new UserBLL();
晕哦···第一次见到你这种写法哦··
就是把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 (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(){}这里面
楼主你用的或者,应该用并且&&
if (textName.Text.Trim() == ""&& textAge.Text.Trim() == "" && textAddress.Text.Trim() == "" && textPwd你那样有一个不为空程序就走了
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();
}
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{
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();
}
}