用C#  .net web怎样在Button里面写代码判断TextBox里面的登录名和密码与数据库中的相比较,如果输入框中的内容与数据库的一致,则能跳转到一个主页。

解决方案 »

  1.   

    很多种方法 例如: 写一个查询方法 然后查询数据库中 有没有你传入的 登录名和密码 如果有 返回一条数据 存进集合里面 判断集合的count 如果>0 则此用户存在~ 
    这是最简单 也是 最不严谨的~ 
      

  2.   

    这种方法试过了  总是出现错误竟然
     protected void Button1_Click(object sender, EventArgs e)
            {
                string name = TextBox1.Text.Trim();            string pw = TextBox2.Text.Trim();            DBAcess db = new DBAcess();
                
                string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw);           DataSet ds = new DataSet();           ds = db.GetDataSet(sql);
              
                if(ds.Tables[0].Rows.Count>0){            
                Response.Redirect("http://localhost:49178/important.aspx");
            }看看有什么错误
      

  3.   


    OleDbConnection conn = new OleDbConnection("数据库连接字符串(LZ是操作本地数据库Access吧那我就按你的操作)");
                try
                {
                    conn.Open();
                     string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw);
                    OleDbCommand cmd = new OleDbCommand(sql,conn);
                    OleDbDataAdapter oda = new OleDbDataAdapter();
                    oda.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable();
                    oda.Fill(ds);
                    dt = ds.Tables[0];
                    ................
                }
      

  4.   

    SQL:select count(*)  from student where name='{0}' and pw='{1}'.
    把查到的值返回到CS的Count。
    CS:
    if (Count>0)
    {
       //Continu
    }
    else
    {
     //Back
    }
      

  5.   

    SQL:select count(*) from student where name='0' and pw='1'