用户登录界面已做好,想根据数据库a里的user表里的username和password来判断登录是否合法,合法就做下一步,请问这个判断怎么写?

解决方案 »

  1.   

    SqlConnection sqlconn = 。;
                    
                    SqlCommand sqlcomm = new SqlCommand("select id from admin where
    username='"+username+"' and userpwd='"+userpwd+"'", sqlconn);
                    
                    sqlconn.Open();
                    
                    try
                    {
                        
                        int uid = (Convert.ToInt64)(sqlcomm.ExecuteScalar());                    if (uid > 0)
                        {
                            Session["username"] = uname;
                            Session["uid"] = uid;
                           Response.Redirect("Welcome.aspx");
                        }
                        else
                        {
                            Response.Write("<script language='javascript'>alert('您的用户名或密码错误!');</script>");
                        }                }
                    catch
                    {                }
                    finally
                    {
                        sqlconn.Close();
                    }
      

  2.   

    其他都挺好,就是Convert.ToInt64有点问题,改成32也不行
      

  3.   

    Convert.ToInt32有问题??不知道是错在哪??请楼主说清楚点~!
      

  4.   

    OleDbConnection cnn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\基于窗体的身份验证\\database.mdb");
            if (cnn.State == ConnectionState.Closed)
            {
                cnn.Open();
            }
            OleDbCommand cmd = new OleDbCommand();
            string str = "Select Count(*) from people where user_name='" + username.Text + "'and user_password='" + Password.Text + "'";
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = str;
            cmd.Connection = cnn;
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                if (reader.GetValue(0).ToString() != "1")
                {
                    msg.Text = "Invalid username and password";
                }
                else
                {
                    
                    Response.Redirect("tt.aspx");
                }
            }
      

  5.   

    int uid = (Convert.ToInt32)(sqlcomm.ExecuteScalar());
    'System.Convert.ToInt32(object)' is a 'method' but is used like a 'type'
      

  6.   

    liubinstud(百里透红)  你在哪啊?
      

  7.   

    (Convert.ToInt32)(sqlcomm.ExecuteScalar());
    括弧去掉Convert.ToInt32(sqlcomm.ExecuteScalar());