这是部分程序
SqlConnection cnLogin = new SqlConnection();
string connStr = ConfigurationSettings.AppSettings["SqlServerConnectionString"];
cnLogin.ConnectionString=connStr;
string mySelectQuery = "SELECT 检定员工号,检定员姓名 FROM 检定员信息 where 部门名称='收发室' and 检定员工号=@检定员工号 and 密码=@密码";
SqlCommand mySqlCommand = new SqlCommand();
mySqlCommand.CommandText = mySelectQuery;
mySqlCommand.Parameters.Add(new SqlParameter("@检定员工号",SqlDbType.VarChar,5)).Value = sfPersonNo;
mySqlCommand.Parameters.Add(new SqlParameter("@密码",SqlDbType.VarChar,10)).Value = sfPassword;
mySqlCommand.Connection = cnLogin;                                            try
                                           {
cnLogin.Open();
     SqlDataReader myReader = mySqlCommand.ExecuteReader();
if(myReader.Read())    
{
MainFrm dlgMainFrm=new MainFrm();
dlgMainFrm.sfPersonNo = this.sfPersonNo;
dlgMainFrm.Text = "样品收发系统-操作员:"+myReader[1].ToString();
myReader.Close();
dlgMainFrm.Show();
this.Hide();
}
else
{
this.txtUserId.Text="";
this.txtPassword.Text="";
MessageBox.Show("用户名或密码输入不正确!");
} }
catch (Exception ex)
{
MessageBox.Show("连接到数据库失败!");
}
finally
{
cnLogin.Close();
}