我创建了一个两个textBox 一个Button
 在上面添完帐号和密码应该如何创建连接
让他们到数据库去搜索这个帐号和密码是否真确
如果不正确的话点完button显示 密码或者帐户错误
正确的话则弹出另外一个窗体

解决方案 »

  1.   

    string password=txtPassword.Text.ToString();
    string name=txtUserName.SelectedItem.ToString(); string connecitonString="server=(local);"+"intetrated security=SSPI;"+"database=App";

    string mysql="select 用户名 密码 from usertable";


    SqlConnection myConnection=new SqlConnection(connecitonString);
    myConnection.Open();
    SqlCommand cmd=new SqlCommand(mysql,myConnection);

                string Password=Convert.ToString(cmd.ExecuteScalar());
    if (Password==password)
    {
    frmMain a=new frmMain();
    a.ShowDialog();}
    else 
    {
    MessageBox.Show("密码输入错误!");
    }
    myConnection.Close();
    以上代码仅供参考!
      

  2.   

    以下是我以前做的一个系统登陆的代码,仅供参考
    private void ButGO_Click(object sender, System.EventArgs e)
    {
    if(comboBox1.Text.ToString().Trim()=="请选择")
    {
    MessageBox.Show("请选择服务器!");
    return;
    }

    IniFile ini= new IniFile(Application.StartupPath+@"\database.ini") ;
    ini.IniWriteValue("database","server",comboBox1.Text.ToString ().Trim());
    string query="select count(*) as a from zz_admin where ID='"+this.TxtID.Text+"'";
    con().Open();
    SqlDataAdapter da = new SqlDataAdapter(query,con());
    DataSet ds = new DataSet();
    da.Fill(ds,"zz_admin") ;
    int aa =(int)ds.Tables[0].Rows[0][0];
    con().Close();
    if (aa ==0)
    {
    MessageBox.Show("管理员帐号输入有误,请重新输入!");
    } else
    {
    string query1="select PWD,DEGREE,used from zz_admin where ID='"+this.TxtID.Text+"'";
    SqlDataAdapter da1 = new SqlDataAdapter(query1,con());
    DataSet ds1 = new DataSet();
    da1.Fill(ds1,"zz_admin") ;
    pwd=ds1.Tables["zz_admin"].Rows[0][0].ToString();
    string dgr=ds1.Tables["zz_admin"].Rows[0][1].ToString(); 
    string  used=ds1.Tables["zz_admin"].Rows[0][2].ToString(); 
    if(pwd.Trim() != TxtPWD.Text.Trim())
    {
    MessageBox.Show("管理员密码输入有误,请重新输入!");
    con().Close();
    return;
    }
    if(dgr.Trim() == "信采员")
    {
    MessageBox.Show("权限不足,请联系超级管理员!");
    con().Close();
    return;
    }
    if(used.Trim() != "启用")
    {
    MessageBox.Show("帐号被封,请联系管理员!");
    con().Close();
    return;
    }
    con().Close();
    UserPWD=TxtPWD.Text.Trim();
    UserName=TxtID.Text.Trim();
    wyfxglht frm= new wyfxglht(UserName);
    frm.Show();
    this.Hide();
    }
    }
      

  3.   

    请参照
    http://www.connectionstrings.com
      

  4.   

    做登陆框要用到哪些控件 
    我用的是SQL数据库