title: Using C# to loop through and insert data
body: <p>I have a program that has to loop through a Scenarios database, and for each while loop iteration, update a second Results database.  Here's the segment of code.</p>
  
  <pre><code>    public void TestScenarios(SqlConnection connection)
      {
          using (SqlCommand cmd = new SqlCommand("SELECT * FROM Scenarios", connection))
          {
              SqlDataReader reader = cmd.ExecuteReader();
  
              if (reader.HasRows)
              {
                  while (reader.Read())
                  {
                      string Id = reader["ScenarioID"].ToString();
                      string Data = reader["ScenarioData"].ToString();
                      string Url = reader["ScenarioURL"].ToString();
                      webBrowser1.Navigate(Url);
                      InsertResults(connection, Id);
                  }
              }
  
              reader.Close();
          }
      }
  
      public void InsertResults(SqlConnection conn, string Id)
      {
          using (SqlCommand cmd = new SqlCommand("INSERT INTO Results VALUES(" +
                  "@ResultID, @HasSucceeded, @ScenarioID, @Screenshot)", conn))
          {
              cmd.Parameters.AddWithValue("@ResultID", 0);
              cmd.Parameters.AddWithValue("@HasSucceeded", 0);
              cmd.Parameters.AddWithValue("@ScenarioID", Id);
              cmd.Parameters.AddWithValue("@Screenshot", "screenshot.jpeg");
          }
      }
  </code></pre>
  
  <p>It's not working, and I'm sure I did tons of things wrong, but I'm having trouble finding direction.</p>