title: How can I update my database with a loop by checking whether a column name corresponds with a button name?
body: <p>So I'm making a seat reservation system for a school project and I'm stuck. I'll explain exactly what I'm trying to do. I created this form:</p>
  
  <p><a href="https://i.stack.imgur.com/nZtR9.png" rel="nofollow noreferrer">Seat Reservation Layout</a></p>
  
  <p>As you can see, I created a seat layout. All the seats are buttons. I also created a local SQL database with SeatID (which matches the names of the buttons exactly) and Availability (either True or False).</p>
  
  <p>What I wanted to do is let the user choose seat(s) (which becomes green after clicking on it) and whenever the user clicks on the "OK" button, the seats get reserved, meaning that I want the Availability in my database corresponding with the buttonname and thus, the SeatID, to become False (meaning the seat got reserved). After running the program again, the reserved seats need to be red, on the start, meaning they can not get reserved.</p>
  
  <p>So basically I managed to do it all; My database works, reserved seats are red whenever I run the program etc.</p>
  
  <p>The only thing I can not get working is updating the database with reserved seats.</p>
  
  <pre><code>private void OK_Click(object sender, EventArgs e)
          {
              con.Open();
  
              SqlCommand command;
              SqlDataAdapter adapter = new SqlDataAdapter();
              String sql = "";
  
              command = new SqlCommand(sql, con);
  
              foreach (Button button in buttons)
              {
  
                  if (button.BackColor == Color.Green)
                  {
                      sql = "UPDATE Seats SET Availability='" + "False" + "'WHERE SeatID=" + button.Name;
                      adapter.UpdateCommand = new SqlCommand(sql, con);
                      adapter.UpdateCommand.ExecuteNonQuery();
  
                  }
              }
  
              command.Dispose();
              con.Close();
  
          }
  </code></pre>
  
  <p>Above you see my code where I try to update the databse. I made the list of all buttons called "buttons" and the code above looks through all the buttons and checks whether they're green or not (green == clicked, so ready to be reserved). That is supposed to happen when I click on the "OK" button. When I run this, I get this error message:</p>
  
  <p><a href="https://i.stack.imgur.com/g3cka.png" rel="nofollow noreferrer">Error Message</a></p>
  
  <p>So, what am I doing wrong? How am I supposed to update the database by checking whether the SeatID corresponds with the button name?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Here I attach my database:</p>
  
  <p><a href="https://i.stack.imgur.com/mm7Kn.png" rel="nofollow noreferrer">Datatable</a></p>
  
  <p><a href="https://i.stack.imgur.com/BoK8E.png" rel="nofollow noreferrer">Data</a></p>