title: Unhandled Format Exception with string
body: <p>The code below is for updating the value in a database,</p>
  
  <pre><code>          string updateCom = ("UPDATE Login SET Username = '" + textUsername.Text + "', Password = '" + textPassword.Text + "', Role = '" + comboBox1.Text + "', First_Name = '" + char.Parse(textFirstName.Text) + "', Last_Name = '" + char.Parse(textLastName.Text) + "', Age = " + int.Parse(textAge.Text) + "', Gender = " + char.Parse(textAge.Text) + " WHERE User_ID = " + textUser_ID.Text);
  </code></pre>
  
  <p>the whole thing is enclosed in a try catch method and upon debugging i got </p>
  
  <blockquote>
    <p>"FormatException was Unhandled"</p>
  </blockquote>
  
  <p>, it also says that string must be exactly one character long. This unhandled exception only happens when i input "John Harambe" as the first name. Can anyone enlighten me on the correct format?</p>
  
  <p>MY SOLUTION TO MY QUESTION:</p>
  
  <p>so i used Parameterized Query as suggested by one of the commenters, here is my code so far;</p>
  
  <pre><code>       updateCom = new SqlCommand("UPDATE Login"
              + "SET Username = @username,"
              + "Password = @password,"
              + "Role = @role,"
              + "First_Name = @firstName,"
              + "Last_Name = @lastName,"
              + "Age = @age,"
              + "Gender = @gender"
              + "WHERE User_ID = @user_ID");
  
          updateCom.Connection = searchCon;
          searchCon.Open();
  
          String Username = textUsername.Text;
          String Password = textPassword.Text;
          String Role = comboBox1.Text;
          String First_Name = textFirstName.Text;
          String Last_Name = textLastName.Text;
          String Age = textAge.Text;
          String Gender = textGender.Text;
  
          if (searchCon.State == ConnectionState.Open)
          {
              updateCom.Parameters.AddWithValue("@username", Username);
              updateCom.Parameters.AddWithValue("@password", Password);
              updateCom.Parameters.AddWithValue("@role", Role);
              updateCom.Parameters.AddWithValue("@firstName", First_Name);
              updateCom.Parameters.AddWithValue("@lastName", Last_Name);
              updateCom.Parameters.AddWithValue("@age", Age);
              updateCom.Parameters.AddWithValue("@gender", Gender);
  
              try
              {
                  updateCom.ExecuteNonQuery();
                  if (MessageBox.Show("Data UPDATED.", "Admin Power",
                      MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                  {
                      searchCon.Close();
                  }
                  else
                  {
                      if(MessageBox.Show("Data NOT UPDATED", "Admin Power",
                          MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                      {
                          return;
                      }
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
              finally
              {
                  searchCon.Close();
              }
          }
  </code></pre>
  
  <p>and it still throws and unhandled exception</p>
  
  <blockquote>
    <p>"Error syntax near 'Username'."</p>
  </blockquote>