具体信息,如题所述~~
有没有谁帮忙解答,给出解决代码或方案,最好是代码,谢谢了!!!
现给出代码如下:
这是登录按钮的:
if (this.textBox1.Text != "" && this.textBox2.Text != "")
            {
                string str = "select * from user_info";
                DataBase db = new DataBase();
                DataSet ds = db.select(str);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].Equals(this.textBox1.Text)&&ds.Tables[0].Rows[i][1].Equals(this.textBox2.Text))
                    {
          
                        login = true;
                    
                    }
                    
                }
                if (login == false)
                {
                    MessageBox.Show("用户信息不存在");
                }

解决方案 »

  1.   

    1.去看看书...看看Equals是什么意思...再看看string的Equals方法和其他引用类型的Equals方法有什么不同...2.去看看书...想想ds.Tables[0].Rows[i][0]是什么类型...3.类似用户登录这种比对数据库只需要一个返回结果的...不需要用DataSet这么“浪费”的对象...DbCommand.ExecuteScalar方法或DbCommand.ExecuteReader方法就足够了...
      

  2.   

                    string str = "select * from user_info"; 
                    DataBase db = new DataBase(); 
                    DataSet ds = db.select(str); 还没学过以上这种方法我只会用SqlConnection 的联接
    我的解决方法是:(如果你用的是SQL数据库)
     string str = "select * from user_info"; 
     SqlConnection con=new SqlConnection("server=.;database=数据库名;uid=用户名;pwd=密码");
     DataSet sd=new DataSet();
     DataAdapter da=new DataAdapter(str,con);
     da.Fill(sd);
     得到结果集上面的就一样了
      顺便请教一下: 
        我朋友开了一家网店!开了一段时间,可没有多少人去买!我对经商不懂!如果您有空,请帮忙提点建议!非常感谢!她的网址是:http://shop35772943.taobao.com 再次感谢!
      

  3.   

     for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 

     if (ds.Tables[0].Rows[i][0].Equals(this.textBox1.Text)&&ds.Tables[0].Rows[i][1].Equals(this.textBox2.Text)) 

              
     login = true; 
                        
     } } 
    改為這樣就可以了,我試過了:
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 

     if (ds.Tables[0].Rows[i][0].ToString()==(this.textBox1.Text)&& ds.Tables[0].Rows[i][1].ToString()==(this.textBox2.Text)) 

    login = true;
    break;   //不加這會有一個問題,最後一行返回不是true的話,那麼最後也會提示沒有些用戶存在
    }} 
                        
     
      

  4.   

    ds.Tables[0].Rows[i][0]是對像類型要轉換一下
      

  5.   

    用户名 密码在数据库里的数据类型都是定义过的 不是简单的用EQUALS验证文本框里的字符串来验证的
    另外做登录只要查询是否有该用户就行了 返回个SQL命令COUNT(*)!=0不就可以了么
      

  6.   

    你可以这样啊 string str = "select * from user_info where username='"+TextBox1.Text+"' and userpwd='"
                            +TextBox2.Text"'"+;
    然后用一楼的DbCommand.ExecuteReader方法
    判断返回的是不是为空就可以了..为空就是用户名不存在或是密码不正确~
      

  7.   

    ds.Tables[0].Rows[i][0].Equals(this.textBox1.Text)
    ds.Tables[0].Rows[i][0].ToString().Trim().Equals();
      

  8.   

    if (this.textBox1.Text != "" && this.textBox2.Text != "") 
                { 
                   string str = "select * from user_info where username='"+TextBox1.Text+"' and userpwd='"+TextBox2.Text+"'"; 
                SqlConnection conn = new SqlConnection();
                conn.Open();
                SqlCommand cmd = new SqlCommand(str,conn);
                string s = cmd.ExecuteNonQuery();
                if (s == "1") { 
                   login=true;
                }
                else   
                 { 
                        MessageBox.Show("用户信息不存在"); 
                    }
    }
      

  9.   

    按照楼主的意思,个人认为应改成这样比较合适。
                if (this.textBox1.Text != "" && this.textBox2.Text != "")
                {
                    SqlConnection conn = new SqlConnection("SqlConnectionString");
                    SqlCommand com = new SqlCommand("SELECT pwd FROM user_info WHERE uid='" + this.textBox1.Text + "'", conn);
                    SqlDataReader reader = com.ExecuteReader();
                    while (reader.Read())
                        if (reader.GetSqlString[0] == this.textBox2.Text)
                            login = true;
                }
      

  10.   

    按照楼主的意思,个人认为改成这样比较合适~            if (this.textBox1.Text != "" && this.textBox2.Text != "")
                {
                    SqlConnection conn = new SqlConnection("SqlConnectionString");
                    SqlCommand com = new SqlCommand("SELECT pwd FROM user_info WHERE uid='" + this.textBox1.Text + "'", conn);
                    SqlDataReader reader = com.ExecuteReader();
                    while (reader.Read())
                        if (reader.GetSqlString[0] == this.textBox2.Text)
                            login = true;
                }
      

  11.   

    select * from user_info where username='"+TextBox1.Text.trim()+"' and userpwd='"+TextBox2.Text.trim()+"'建议你在数据库查询分析器里用sql语句查一下,如果查不到,再检查是不是因为数据库里面的数据两边的空格的原因
      

  12.   

    这两种方法是一样的呀,只是把equals换成=了
    不过还是谢谢