title: Insert and update a datetime into SQL database
body: <pre><code>private void ButtonOk_Click(object sender, EventArgs e)
      {
          if (txtWedstrijdSchemaID.Text == "")
          {
              //Insert
              string SQL;
              SQL = "Insert into Wedstrijdschema (Team1, Team2, Datum)";
              SQL += " values (";
              SQL += "" + txtTeam1.Text + ",";
              SQL += "" + txtTeam2.Text + ",";
              SQL += "" + Convert.ToDateTime(txtDatum.Text) + "";
              SQL += ")";
  
              clDatabase.ExecuteCommand(SQL);
              vulLv();
          }
          else
          {
              //Update
              string SQL;
              SQL = "Update Wedstrijdschema SET ";
              SQL += "Team1 = " + txtTeam1.Text + ",";
              SQL += "Team2 = " + txtTeam2.Text + ",";
              SQL += "Datum = " + Convert.ToDateTime(txtDatum.Text) + "";
              SQL += " where SchemaId = " + zoek;
  
              clDatabase.ExecuteCommand(SQL);
              vulLv();
          }
          txtDatum.Enabled = txtTeam2.Enabled = txtTeam1.Enabled = false;
      }
  </code></pre>
  
  <p>That is what I currently have, because of a trycatch it won't crash when I try, if I comment the txtDatum.Text out on the //insert and //upload it works (but obviously enters NULL for Datum in the Database) does anyone perhaps see where I'm going wrong?</p>
  
  <p>EDIT: About the use of parameters, we need to use a threetier system where all SQL goes through a class which is the only one allowed to do anything with the database, this is how the command is executed:</p>
  
  <pre><code>public static bool ExecuteCommand(string SQLInstructie)
          {
              bool retour = true;
              SqlConnection Conn = new SqlConnection(clStam.Connstr);
              SqlCommand Cmd = new SqlCommand(SQLInstructie, Conn);
  
              try
              {
                  Cmd.Connection.Open();
                  Cmd.ExecuteNonQuery();
              }
              catch
              {
                  retour = false;
              }
              finally
              {
                  Conn.Close();
              }
              return retour;
          }
  </code></pre>
  
  <p>This works!! Thanks a lot for the help:</p>
  
  <pre><code>private void ButtonOk_Click(object sender, EventArgs e)
          {
              if (txtWedstrijdSchemaID.Text == "")
              {
                  //Insert
  
                  string SQL;
                  SQL = "Insert into Wedstrijdschema (Team1, Team2, Datum)";
                  SQL += " values (";
                  SQL += "" + txtTeam1.Text + ",";
                  SQL += "" + txtTeam2.Text + ",";
                  SQL += "'" + Convert.ToDateTime(txtDatum.Text) + "'";
                  SQL += ")";
                  Debug.WriteLine(SQL);
                  clDatabase.ExecuteCommand(SQL);
                  vulLv();
              }
              else
              {
                  //Update
                  string SQL;
                  SQL = "Update Wedstrijdschema SET ";
                  SQL += "Team1 = " + txtTeam1.Text + ",";
                  SQL += "Team2 = " + txtTeam2.Text + ",";
                  SQL += "Datum = '" + Convert.ToDateTime(txtDatum.Text) + "'";
                  SQL += " where SchemaId = " + zoek;
  
                  clDatabase.ExecuteCommand(SQL);
                  vulLv();
              }
              txtDatum.Enabled = txtTeam2.Enabled = txtTeam1.Enabled = false;
          }
  </code></pre>
  
  <p>EDIT: I'll promise to use parameterized SQL from now on!</p>