http://expert.csdn.net/Expert/topic/1957/1957958.xml?temp=.7107202

解决方案 »

  1.   

    可能使这样的吧://User,UID,UPWS,JB是全局string变量
    //t_uid,t_upws是登陆框的用户名和密码文本框
    string s_uid=t_uid.Text.Trim();
    string s_upws=t_upws.Text.Trim();
    string connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=路径\aa.mdb";
    OleDbConnection conn=new OleDbConnection(connStr);
    conn.Open();
    string strSql="select * from User where UID='"&s_uid&"' and UPWS='"&s_upws&"'";
    OleDbCommand cmd = new OleDbCommand(strSql,conn);
    OleDbDataReader reader1=cmd.ExecuteReader();
    if(reader1.Read())                   //登陆成功
    {                      
      User=s_uid;
      UPWS=s_upws;
      JB=reader1["JB"].ToString();
      reader1.close();
      conn.close();
      关闭登陆窗口进入主窗口;
    }
    else
      MessageBox("用户不存在或者密码不正确请重新输入!");
      

  2.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    string sql="SELECT * FROM adminguanli";
    string pw=null;
    try
    {
    thisConnection.Open(); SqlCommand thisCommand=thisConnection.CreateCommand();
    thisCommand.CommandText=sql; SqlDataReader thisReader=thisCommand.ExecuteReader(); while(thisReader.Read())
    {
    pw=thisReader["adminpass"].ToString().Trim();
    } thisReader.Close();
    thisConnection.Close(); if(textBox1.Text=="")
    {
    MessageBox.Show("请输入密码!");
    textBox1.Focus();
    }
    else
    {
    if(pw==textBox1.Text)
    {
    panel1.Visible=true;
    button3.Focus();
    }
    else
    {
    MessageBox.Show("您输入的密码不正确,请重新输入!");
    textBox1.Text=null;
    }
    }
    }
    catch
    {
    } }