title: issue looping through SQL table C#
body: <p>My application is reading off a SQL query table and matching and displaying values in certain fields in a listview. My query SQL table looks like this </p>
  
  <pre>
  +--------------+---------+-------+----------+--------+
  | process name | subtask | total | employee |  date  |
  +--------------+---------+-------+----------+--------+
  | process 1    | sub1    |     1 |     1111 | 01-May |
  | process 2    |         |     1 |     2222 | 05-May |
  | process 3    |         |     1 |     3333 | 10-May |
  | process 4    |         |     1 |     4444 | 07-May |
  +--------------+---------+-------+----------+--------+
  
  </pre>
  
  <p>I have run into a problem. I have noticed by stepping through my loops (using messegebox) that process 1 is displayed in my messagebox multiple times (in <code>MessageBox.Show(dr[0].ToString());</code>) when it should only be displayed once and when the loop gets to process 4 the messagebox displays process 4 (in (in <code>MessageBox.Show(dr[0].ToString());</code>)) then the loop stops and thus does not grab the total, employee and date values. How can I fix this. </p>
  
  <p><code></p>
  
  <pre><code>         DateTime now = DateTime.Now;
          var startDate = new DateTime(now.Year, now.Month, 1);
          var endDate = startDate.AddMonths(1).AddDays(-1);
  
  
          string[,] report = new string[,] { {"process 1", "sub1", "3", "0",  "", "" },
         {"process 2", "", "3", "0", "", "" },
         {"process 3", "", "3", "0", "", "" }
          *** there are multiple entries in this array *****
         }  
  
      string totalsquery = "select Process_Name, Sub_Process1_Name, count(id) as total, Completed_By_Employee_Number, max(Refresh_Date)  from testDB.dbo.Quality_Data_Master  where Refresh_Date between '" + startDate + "' and '" + endDate + "' group by Process_Name, Sub_Process1_Name,  Completed_By_Employee_Number, Refresh_Date";
  
  
    SqlConnection con = new SqlConnection();
          SqlDataAdapter ada = new SqlDataAdapter(totalsquery, con);
          DataTable dt = new DataTable();
          ada.Fill(dt);
  
          listView1.View = View.Details;
          listView1.Columns.Add("Process Name", 250);
          listView1.Columns.Add(" Sub Task", 200);
          listView1.Columns.Add("Target", 45, HorizontalAlignment.Center);
          listView1.Columns.Add("Total", 40, HorizontalAlignment.Center);
          listView1.Columns.Add("Employee", 100, HorizontalAlignment.Center);
          listView1.Columns.Add("Date", 100);
  
  
          for (int i = 0; i &lt; dt.Rows.Count; i++)
          {
  
  
              DataRow dr = dt.Rows[i];
  
              //MessageBox.Show(dr.ToString());
              for (int j = 0; j &lt; report.GetLength(0); j++)
              {
  
                  if (report[j, 0].Equals(dr[0].ToString()))
                  {
                      MessageBox.Show(dr[0].ToString());
                      if (report[j, 1].Equals(dr[1].ToString()))
                      {
                          MessageBox.Show(dr[1].ToString());
  
                          report[j, 3] = (Int32.Parse(report[j, 3]) + (int)dr[2]).ToString();
  
                          MessageBox.Show(dr[2].ToString());
  
                          report[j, 4] = report[j, 4] + dr[3].ToString();
                          MessageBox.Show(dr[3].ToString());
  
                          report[j, 5] = report[j, 5] + dr[4].ToString();
  
  
  
                          MessageBox.Show(dr[4].ToString());
                      }
                  }
              }
          }
  
  
  
  
  
          String[] temp = new String[7];
          for (int i = 0; i &lt; report.GetLength(0); i++)
          {
              temp[0] = report[i, 0].ToString();
              temp[1] = report[i, 1].ToString();
              temp[2] = report[i, 2].ToString();
              temp[3] = report[i, 3].ToString();
              temp[4] = report[i, 4].ToString();
              temp[5] = report[i, 5].ToString();
              //temp[6] = report[i, 6].ToString();
  
              ListViewItem listItem = new ListViewItem(temp);
              listView1.Items.Add(listItem);
  
          }
  
              con.Close();
  </code></pre>
  
  <p></code></p>