private void Pawread()
        {
            this.textBox1.Text="";
            string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog = Test;Integrated Security = True;Pooling = False";
            SqlConnection myConnection = new SqlConnection(connectionString);
            myConnection.Open();            SqlCommand myCommand = myConnection.CreateCommand();
            string sql = "select password from t_user where username='"+this.Name+"'";
            myCommand.CommandText = sql;
            SqlDataReader myDataReader = myCommand.ExecuteReader();
            if (myDataReader.HasRows)
            {
                while (myDataReader.Read())
                {
                    string psw = myDataReader["addressname"].ToString();
                }
            }
            myDataReader.Close();
            myConnection.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog=Test;Integrated Security =True;Pooling =False";            SqlConnection myConnection = new SqlConnection(connectionString);
            myConnection.Open();            SqlCommand myCommand = myConnection.CreateCommand();
            string sql = "select password from t_user where username='" + this.Name + "'";            myCommand.CommandText = sql;
            myCommand.ExecuteNonQuery();
            myConnection.Close();
            if (textBox1.Text == Pawread( ))
            {
                if (textBox2.Text == textBox3.Text)
                {
                    string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog=Test;Integrated Security =True;Pooling =False";
                    SqlConnection myConnection = new SqlConnection(connectionString);
                    myConnection.Open();                    SqlCommand myCommand = myConnection.CreateCommand();
                    string sql = "update t_user set password='" + textBox2.Text + "'where username='" + this.Name + "'";
                    myCommand.CommandText = sql;
                    myCommand.ExecuteNonQuery();
                    myConnection.Close();
                }
                else
                {
                    MessageBox.Show("两次输入密码不同!");
                }
            }
            else
            {
                MessageBox.Show("原始密码不正确!");
                textBox1.Text = "";
                textBox1.Focus();
            }
        }
提示红色部分错误错误 1 运算符“==”无法应用于“string”和“void”类型的操作数
运算符“==”的用法我可以查到  主要想请大侠们指导该问题具体该如何解决我的目的是修改密码   先验证旧密码的正确性   请不吝赐教  谢谢谢谢

解决方案 »

  1.   

      if (textBox1.Text == Pawread( )) string paw = (string)myCommand.ExecuteNonQuery(); 
    if(textBox1.Text.Trim()==paw)
      

  2.   

    1楼正解...不过貌似可以用用这个参数...
                String a = "123";
                String b = "123";
                //a.Equals()方法代替 "==" 运算符
                  a.Equals(b);
      

  3.   

    你没有返回值  private string Pawread() 
            { 
                this.textBox1.Text=""; 
                string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog = Test;Integrated Security = True;Pooling = False"; 
                SqlConnection myConnection = new SqlConnection(connectionString); 
                myConnection.Open();             SqlCommand myCommand = myConnection.CreateCommand(); 
                string sql = "select password from t_user where username='"+this.Name+"'"; 
                myCommand.CommandText = sql; 
                SqlDataReader myDataReader = myCommand.ExecuteReader();             if (myDataReader.HasRows) 
                { 
                    while (myDataReader.Read()) 
                    { 
                        string psw = myDataReader["addressname"].ToString(); 
                    } 
                } 
                myDataReader.Close(); 
                myConnection.Close(); 
             return psw;
            } 
    这样就不会错了
      

  4.   


    private string  Pawread() 

         string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog = Test;Integrated Security = True;Pooling = False"; 
         SqlConnection myConnection = new SqlConnection(connectionString); 
         myConnection.Open();      SqlCommand myCommand = myConnection.CreateCommand(); 
         string sql = "select password from t_user where username='"+this.Name+"'"; 
         myCommand.CommandText = sql; 
         SqlDataReader myDataReader = myCommand.ExecuteReader(); 
         string psw = "";
         if (myDataReader.HasRows) 
         { 
              while (myDataReader.Read()) 
              { 
                  psw= myDataReader["addressname"].ToString(); 
              } 
         } 
         myDataReader.Close(); 
         myConnection.Close(); 
         return psw;

    private void button1_Click(object sender, EventArgs e) 

         if (textBox1.Text == Pawread( )) 
         { 
              if (textBox2.Text == textBox3.Text) 
              { 
                    string connectionString = @"Data Source = CHINA-2FD3DC67C;Initial Catalog=Test;Integrated Security =True;Pooling =False"; 
                    SqlConnection myConnection = new SqlConnection(connectionString); 
                    myConnection.Open();                 SqlCommand myCommand = myConnection.CreateCommand(); 
                    string sql = "update t_user set password='" + textBox2.Text + "'where username='" + this.Name + "'"; 
                    myCommand.CommandText = sql; 
                    myCommand.ExecuteNonQuery(); 
                    myConnection.Close(); 
               } 
               else 
               { 
                    MessageBox.Show("两次输入密码不同!"); 
               } 
           } 
           else 
           { 
                MessageBox.Show("原始密码不正确!"); 
                textBox1.Text = ""; 
                textBox1.Focus(); 
           } 
    }