DataTable dtSQL = new DataTable();
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        sda.Fill(dtSQL);
        foreach (dtSql.Rows r in dtSQL)
        {
            if (r.Columns["PreId"] == preID)
            {
                this.TextBox1.Text = "";
                this.Label1.Text = "abc";            }
        }foreach()里报错

解决方案 »

  1.   

     if (r.Columns["PreId"].ToString() == Convert.ToString(preID))
      

  2.   

    现在是FOREACH里面报错        foreach(Row r in dtSQL.Rows)括号里的Row 红线
      

  3.   

    foreach (DataRow r in dtSQL)
      {
      if (r["PreId"] == preID)
      {
      this.TextBox1.Text = "";
      this.Label1.Text = "abc";  }
      }
      

  4.   

     foreach (dtSql.Rows r in dtSQL)
      {
      if (object.Equals(r.Columns["PreId"],preID))
      {
      this.TextBox1.Text = "";
      this.Label1.Text = "abc";
      break;
      }
      }
      

  5.   

    foreach (var  r in dtSQL)
      {
      if (object.Equals(r.Columns["PreId"],preID))
      {
      this.TextBox1.Text = "";
      this.Label1.Text = "abc";
      break;
      }
      }
      

  6.   

    foreach (var r in dtSQL)
      {
      if (object.Equals(r.Columns["PreId"],preID))
      {
      this.TextBox1.Text = "";
      this.Label1.Text = "abc";
      break;
      }
      }Columns 报错
      

  7.   


    DataTable dtSQL = new DataTable();
      SqlDataAdapter sda = new SqlDataAdapter(cmd);
      sda.Fill(dtSQL);
      foreach (DataRow r in dtSQL.Rows)
      {
      if ((string)r["PreId"] == preID)
      {
      this.TextBox1.Text = "";
      this.Label1.Text = "abc";  }
      }