看看这个吧!
string qw = "select * from dengru where zhanghao=@a and mima=@b";
SqlConnection sqlcon = new SqlConnection("server=.;database=qiyexinxi;uid=sa;pwd=123456");
if (textBox1.Text == "")
{
MessageBox.Show("请您输入密码!");
}
else
{
try
{
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand(qw, sqlcon);
SqlParameter[] sqldt = new SqlParameter[]
{
new SqlParameter ("@a",comboBox1 .Text.ToString ()),
new SqlParameter ("@b",textBox1 .Text.ToString () )
};
sqlcom.Parameters.AddRange(sqldt);
int aa = Convert.ToInt32(sqlcom.ExecuteScalar());
if (aa > 0)
{
timer1.Enabled = false;
timer1.Stop();
主窗体 fgh = new 主窗体();
fgh.Show();
this.Visible = false;
}
else
{
MessageBox.Show("密码错误!请核对后重新登入···");
}