title: remove over space char in textbox while editing
body: <p>I set my database(.mdf)  Firstname to (nchar(30)) and Middlename to nchar(30) same to Lastname and Age to nchar(3) ang sex nchar(6) </p>
  
  <p>now the problem is when i save a new record to my database.. 
  example: i save (firstname)="Perdo" (Middlename)="Calungsod" (lastname)="Madrigal"</p>
  
  <p>after I save the record it will consume all 30 character that i set and save 
  example 
  when i save (Firstname)="Pedro" and when you try to edit the record the you will notice the spacing like this ["pedro                        "] like that so i count all the spacing .. the total is 30 including the "pedro" .. so what i want to happen is to delete the white space </p>
  
  <p>im using (VS2010)ASP.NET C#</p>
  
  <p>here's my code for saving </p>
  
  <pre><code>        protected void Button1_Click(object sender, EventArgs e)
      {
  
          if (save_B.Text == "SAVE")
          {
              try
              {
  
                  //ID NUMBER GENERATES
                  var chars = "0123456789";
                  var random = new Random();
                  var newGUID = new string(
                      Enumerable.Repeat(chars, 8)
                                .Select(s =&gt; s[random.Next(s.Length)])
                                .ToArray());
  
                  // SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["User_DB_Connectionstring"].ConnectionString);
  
                  conn.Open();
  
                  string checkuser = "Select count(*) from User_TBL_DB where Firstname='" + T_firstName.Text + "' and Middlename='" + T_middlename.Text + "' and Lastname='" + T_lastname.Text + "' or ID='" + newGUID + "'";
  
                  SqlCommand cmd = new SqlCommand(checkuser, conn);
                  cmd.Connection = conn;
  
                  int temp = Convert.ToInt32(cmd.ExecuteScalar());
                  if (temp == 1)
                  {
                      Response.Write("User Already Exist");
                  }
                  else
                  {
  
                      try
                      {
                          string Male = "MALE";
                          string Female = "FEMALE";
                          string insertQuery = "insert into User_TBL_DB (Firstname,Middlename,Lastname,Age,Sex,ID) values (@first,@middle,@last,@age,@sex,@id)";
                          SqlCommand com = new SqlCommand(insertQuery, conn);
  
  
                          if (string.IsNullOrEmpty(T_firstName.Text))
                          {
                              T_firstName.Focus();
                          }
                          else if (string.IsNullOrEmpty(T_middlename.Text))
                          {
                              T_middlename.Focus();
                          }
                          else if (string.IsNullOrEmpty(T_lastname.Text))
                          {
                              T_lastname.Focus();
                          }
                          else if (string.IsNullOrEmpty(T_age.Text))
                          {
                              T_age.Focus();
                          }
  
                          else if (male_b.Checked)
                          {
                              com.Parameters.AddWithValue("@sex", Male);
                              com.Parameters.AddWithValue("@first", T_firstName.Text);
                              com.Parameters.AddWithValue("@middle", T_middlename.Text);
                              com.Parameters.AddWithValue("@last", T_lastname.Text);
                              com.Parameters.AddWithValue("@age", T_age.Text);
  
                              com.Parameters.AddWithValue("@id", newGUID);
                              com.ExecuteNonQuery();
                              Response.Write("User Registration Accepted");
                              Response.Redirect("index.aspx");
  
                              conn.Close();
                              conn.Open();
                              conn.Close();
                          }
                          else if (female_b.Checked)
                          {
                              com.Parameters.AddWithValue("@sex", Female.Trim());
                              com.Parameters.AddWithValue("@first", T_firstName.Text.Trim());
                              com.Parameters.AddWithValue("@middle", T_middlename.Text.Trim());
                              com.Parameters.AddWithValue("@last", T_lastname.Text.Trim());
                              com.Parameters.AddWithValue("@age", T_age.Text.Trim());
  
                              com.Parameters.AddWithValue("@id", newGUID.Trim());
                              com.ExecuteNonQuery();
                              Response.Write("User Registration Accepted");
                              Response.Redirect("index.aspx");
  
                              conn.Close();
                              conn.Open();
                              conn.Close();
                          }
                          else
                          {
                              Response.Write("Error Saving Please Try Again");
  
                          }
  
  
                      }
                      catch (Exception ex)
                      {
                          Response.Write("Error:" + ex.ToString());
                      }
  
  
                  }
  
  
                  conn.Close();
              }
              catch (Exception ec)
              {
                  Response.Write("Error Again to:" + ec.ToString());
              }
          }
  
          else if (save_B.Text == "UPDATE")
          {
              try
              {
                  conn.Open();
                  string Genderselect;
                  if (male_b.Checked)
                  {
                      Genderselect = "MALE";
                  }
                  else
                  {
                      Genderselect = "FEMALE";
                  }
  
                  string checkuser = "Select count(*) from User_TBL_DB where Firstname='" + T_firstName.Text + "' and Middlename='" + T_middlename.Text + "' and Lastname='" + T_lastname.Text + "' and Sex='"+Genderselect+"' and Age='"+T_age.Text+"' ";
  
                  SqlCommand cmd = new SqlCommand(checkuser, conn);
                  cmd.Connection = conn;
  
                  int temp = Convert.ToInt32(cmd.ExecuteScalar());
                  if (temp == 1)
                  {
                      Response.Write("Nothing Changed");
                  }
                  else
                  {
                      string Male = "MALE";
                      string Female = "FEMALE";
                      //conn.Open();
  
                      string updateData = "UPDATE [User_TBL_DB] set [Firstname]=@Firstname, [Middlename]=@Middlename,[Lastname]=@Lastname,[Age]=@Age,[Sex]=@Sex where [ID]=@ID";
                      SqlCommand com = new SqlCommand(updateData.Trim(), conn);
                      if (string.IsNullOrEmpty(T_firstName.Text))
                      {
                          T_firstName.Focus();
                      }
                      else if (string.IsNullOrEmpty(T_middlename.Text))
                      {
                          T_middlename.Focus();
                      }
                      else if (string.IsNullOrEmpty(T_lastname.Text))
                      {
                          T_lastname.Focus();
                      }
                      else if (string.IsNullOrEmpty(T_age.Text))
                      {
                          T_age.Focus();
                      }
  
                      else if (male_b.Checked)
                      {
                          com.Parameters.AddWithValue("@Sex", Male.Trim());
                          com.Parameters.AddWithValue("@Firstname", T_firstName.Text.Trim());
                          com.Parameters.AddWithValue("@Middlename", T_middlename.Text.Trim());
                          com.Parameters.AddWithValue("@Lastname", T_lastname.Text.Trim());
                          com.Parameters.AddWithValue("@Age", T_age.Text.Trim());
  
                          com.Parameters.AddWithValue("@ID", ID_label.Text.Trim());
                          com.ExecuteNonQuery();
                          Response.Write("User Registration Accepted");
                          Response.Redirect("index.aspx");
  
                          conn.Close();
                          conn.Open();
                          conn.Close();
                      }
                      else if (female_b.Checked)
                      {
                          com.Parameters.AddWithValue("@Sex", Female.Trim());
                          com.Parameters.AddWithValue("@Firstname", T_firstName.Text.Trim());
                          com.Parameters.AddWithValue("@Middlename", T_middlename.Text.Trim());
                          com.Parameters.AddWithValue("@Lastname", T_lastname.Text.Trim());
                          com.Parameters.AddWithValue("@Age", T_age.Text.Trim());
  
                          com.Parameters.AddWithValue("@ID", ID_label.Text.Trim());
  
                          com.ExecuteNonQuery();
                          Response.Write("User Registration Accepted");
                          Response.Redirect("index.aspx");
  
                          conn.Close();
                          conn.Open();
                          conn.Close();
                      }
                      else
                      {
                          Response.Write("Error Saving Please Try Again");
  
                      }
  
  
  
                  }
              }
              catch (Exception x)
              {
                  Response.Write(x.ToString());
              }
          }
  
      }
  </code></pre>
  
  <p>I included all the validations.. i use trim too but it's not working or im not using it right hehe thank you for reading this and i hope you have the answer to my question have a nice day </p>