//1个button 2个textbox
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand comm=conn.CreateCommand();
comm.CommandText=CommandType.Text.ToString();
if(this.textBox1.Text.Length==0)
{
MessageBox.Show("用户不能为空,请查询后输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select count(*) from paimai where paihao='"+this.textBox1.Text+"'";
conn.Open();
if((int)comm.ExecuteScalar()==0)
/*
第一次点BUTTON后 可以出来MESSAGEBOX 第二次就提示错误
错误提示: 连接已经打开(state=Open)
*/
{
MessageBox.Show("不存在此用户,请检查后重新输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select paihao,mima from paimai where paihao='"+this.textBox1.Text+"'";
SqlDataReader read = comm.ExecuteReader();
if(read.Read())
{
if(this.textBox2.Text==read[0].ToString() && textBox1.Text.Length != 0)
{
MessageBox.Show("登录成功","恭喜",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
else 

MessageBox.Show("用户" + textBox1.Text + "的密码不正确","密码",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning); 
textBox2.Focus(); 
return; 
}
}
conn.Close();
this.textBox1.Text="";
this.textBox2.Text="";