C#如何判断执行后的结果?
deria 2006-05-13 03:06:11 现在写了个用户验证的窗体,发现不知道如何判断执行后的结果,用如下这种方法写输入对和错的都能登录上,不知应该那个判断结果应如何写,谢谢了!
private void button1_Click(object sender, System.EventArgs e)
{
dblink newlink=new dblink();
SqlConnection myConn=new SqlConnection(newlink.strconn);
myConn.Open();
SqlCommand cmd =myConn.CreateCommand();
cmd.CommandText="select PWD,GID from userlist where id='"+
txtUser.Text.Trim()+ "' and pwd='"+txtPwd.Text.Trim()+"'";
try
{
object result=cmd.ExecuteScalar();
if (result!=System.DBNull.Value)
{
MessageBox.Show("登录成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Visible=false;
MainFrm newMain= new MainFrm();
newMain.ShowDialog();
}
else
{
MessageBox.Show("用户名或密码错误","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
}