namespace BANK
{
public partial class Formc : Form
{
public Formc()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox3.Text == ""|| textBox2.Text == "")
MessageBox.Show("提示:请输入完整信息!", "警告");
char Card_id = char.Parse(this.textBox2.Text);
double money = double.Parse(this.textBox1.Text);
string up = "update DemDeposit set Saving_money='" + money + "' where Card_ID='" + Card_id + "'";
SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=bank;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Client_info where Card_ID='" + textBox1.Text.Trim() + "' and Card_p='" + textBox3.Text.Trim() + "'", conn);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
if (sdr.HasRows)
{
SqlCommand mycom = new SqlCommand(up, conn);
mycom.ExecuteNonQuery(); //执行更新语句
conn.Close();
}
else
MessageBox.Show("提示:学生卡名或密码错误!", "警告");
conn.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
}
}
什么都不输入,点确定应该输出MessageBox.Show("提示:请输入完整信息!", "警告");但没反应,取消也没反应
看下事件注册成功没有。右键“button1_Click”查看引用。看看有没有下面这样的一句代码:
this.button1.Click+=new new System.EventHandler(this..button1_Click)
用KEYDOWN事件是不是更好点 而且判断要用 if(e.keycode != keys.enter) return