title: C# Inserting values into database using switch case
body: <p>I am trying to insert values into the database using a switch case. In some cases there might be more than one value that has to be inserted for a particular case. I am unable to insert both the values corresponding to a case. </p>
  
  <pre><code>foreach (int thisColor in allColors)
  {
      List&lt;Subject&gt; subjectsForThisColor = subjects.Where(x =&gt; x.Color == thisColor).ToList();
      foreach (Subject s in subjectsForThisColor)
      {
          test += s.SubjectName + " -" + s.Color + "\n";
          switch (s.Color)
          {
              case 1:
                  con.Open();
                  SqlCommand cmd = new SqlCommand("INSERT INTO Monday (first) values (@first)",con);
                  cmd.Parameters.AddWithValue("first",s.SubjectName);
                  cmd.ExecuteNonQuery();
                  con.Close();
                  break;
              case 2:
                  con.Open();
                  SqlCommand cmd1 = new SqlCommand("UPDATE  Monday set [second] = @second", con);
                  cmd1.Parameters.AddWithValue("second", s.SubjectName);
                  cmd1.ExecuteNonQuery();
                  con.Close();
                  break;
              case 6:
                  con.Open();
                  SqlCommand cmd6 = new SqlCommand("UPDATE  Monday set [sixth] = @sixth", con);
                  cmd6.Parameters.AddWithValue("sixth", s.SubjectName);
                  cmd6.ExecuteNonQuery();
                  con.Close();
                  break;
          }
      }
  }
  </code></pre>
  
  <p>here are the case values :</p>
  
  <pre><code>    C#           1
      SSM          2
      OOMD         3
      MMT          4
      Elective-1   5
      Elective-2   6
      Elective-5   6
      Elective-3   7
      Elective-4   8
      Elective-6   8
  </code></pre>
  
  <p>So when I encounter case 6, I need to insert the values <code>Elective -2</code> and also <code>Elective -5</code>. Right now I am able to insert only <code>Elective-5.</code></p>