有人有关于C#登录窗口连接SQL Server 2000的源代码吗?]
本人初学者,在判断成功登录\用户名和密码错误这里卡住了
希望大家给点意见,谢谢了

解决方案 »

  1.   

    string name=Request.Form["username"];
       string pass=Request.Form["password"];
       SqlConnection conn=new SqlConnection("server=服务器名字iis;uid=sa;pwd=123456;database=数据库名");
       conn.Open();
       string sql="select * from 表名";   
       SqlCommand myCommand= new SqlCommand(sql,conn);
       SqlDataReader rstobj=myCommand.ExecuteReader();
       try{   if(rstobj.Read()){
    Response.Write("登陆成功");
    }
       
       
       }    
       catch(Exception ex)
       {
        Response.Write(ex.Message);
       }
       finally
       {
        rstobj.Close();
        conn.Close();
       }
      

  2.   

    winform?
    reference
    http://blog.csdn.net/knight94/archive/2006/04/06/652394.aspx
      

  3.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    user_id = USER_ID.Text;
    if(user_id == "")
    {
    MessageBox.Show("please input USER_ID");
    return;
    } string user_pwd = USER_PWD.Text;
    if(user_pwd == "")
    {
    MessageBox.Show("please input password");
    return;
    }
    string strSQL;

    strSQL = "SELECT * FROM A2_USER WHERE USER_ID = '" + user_id + "'";

    SqlDataAdapter da = new SqlDataAdapter(strSQL, source);
    DataSet ds = new DataSet();
    da.Fill(ds,"USER");
    try
    {
    if(ds.Tables["USER"].Rows.Count != 0)
    {
    if(ds.Tables["USER"].Rows[0]["USER_PWD"].ToString() == user_pwd.ToString())
    {
    this.Hide();
    contract myForm = new contract();
    myForm.ShowDialog();
    this.Close();
    }
    else
    {
    MessageBox.Show("password is wrong,please enter correct password");
    return;
    }
    }
    else
    {
    MessageBox.Show("Not exist this user");
    return;
    }
    }
    catch(System.Exception err)
    {
    MessageBox.Show(err.Message);
    }

    finally
    {

    }

    }
      

  4.   

    要加上数据库连接:
    string source = ".........";
      

  5.   

    private void loginqueding_Click(object sender, System.EventArgs e)
    {


    if(textBox2.Text==""||comboBox1.Text=="")
    MessageBox.Show("用户名或密码为空!!");
    else
    { try
    {

    string str="server=.;database=renshi;Integrated Security=True;";
    SqlConnection con=new SqlConnection(str);
    int res=0;
    string  pssd=textBox2.Text.ToString().Trim();
    con.Open();
    string cmdText="select  * from userlist where name='"+username+"'and psd='"+pssd+"'  ";
    SqlCommand cmd=new SqlCommand();
    cmd.CommandText=cmdText;
    cmd.Connection=con;
    SqlDataReader sqldr=null;
    sqldr=cmd.ExecuteReader();
    sqldr.Read();

    string ss=sqldr["name"].ToString().Trim();
    ppow=sqldr["qxian"].ToString().Trim();
    pssd=sqldr["psd"].ToString().Trim();
    //MessageBox.Show(pssd);
    //ppow=tmppow;


    if(ss==username)
    res=1;
    if(res==1)
    { this.Hide();
    //Application.Exit();
    Form1 f1=new Form1();
    f1.tmppower=ppow;
    f1.yuanmima=pssd;
    f1.tmpname=ss;//name
    f1.Show();

    }
    else
    {
    MessageBox.Show("code0err");
    //textBox2.Text=res.ToString();
    }


    }
    catch(Exception ex)
    {
    string nn=ex.Message.ToString();
    //MessageBox.Show(nn);
    MessageBox.Show("用户名或密码错误!!");
    textBox2.Text="";
    //comboBox1.Text="";
    }
    finally
    {
    //sqldr.Close();
    //con.Close();
    //MessageBox.Show(ppow);
        }
    }
    }