我在"保存修改"按钮中用了以下IF语句,作用是先判断两个文本框是不是为空,如果不空的话,就保存.现在是保存没有问题,只是当两个文本框为空时,判断失效.
以下是代码:
if (this.textBox2.Text == "")
{
MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.textBox2.Focus();
}
else
{
if (this.textBox4.Text == "")
{
MessageBox.Show("水表名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.textBox2.Focus();
}
else
{
mybase.getcom("update sbxx set dwmc='" + this.textBox2.Text.Trim() + "',sbmc='" + this.textBox4.Text.Trim()
+ "',yhlx='" + this.comboBox2.Text.Trim() + "',sblx='" + this.comboBox1.Text.Trim()
+ "',Phone='" + this.textBox3.Text.Trim() + "',dizhi='" + this.textBox5.Text.Trim()
+ "',zzs='" + this.comboBox3.Text.Trim() + "' where dwbh = '" + this.textBox1.Text.Trim() + "' and sbbh='" + this.textBox6.Text.Trim() + "'");
this.button1_Click(sender, e);
MessageBox.Show("水表用户信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}