异常处理

private void btnOK_Click(object sender, EventArgs e)
{
btnOK.Enabled = false;
try
{
DataTable dt = userBal.GetTable(" UserName='" + txtUserName.Text.ToString().Trim() + "' and UserPwd='" + txtUserPwd.Text.ToString().Trim() + "'");
if (dt.Rows.Count > 0)
{
UserSate.userid = dt.Rows[0]["ID"].ToString();
UserSate.userpower = dt.Rows[0]["UserPower"].ToString();
frmMain frm = new frmMain();
frm.Show();
this.Hide();
}
else
{
MessageBox.Show("对不起,用户名或密码不对!");
}
}
catch
{
MessageBox.Show("对不起,用户名或密码错误!");
}
finally
{
btnOK.Enabled = true;
}
}

posted @ 2016-10-25 11:32  爱编程1314  阅读(96)  评论(0编辑  收藏  举报