[Solved] SQL server remove space before value when I insert data


Of course any kind of problems surface when you use string concatenation to build command text. In your case you have inadvertently added a space before your control values.
If you had used a parameterized query this problem would not have arisen

  SqlCommand cmd1 = new SqlCommand("INSERT INTO [Contracts].[dbo].[Contract] " + 
     "([Contract_Id],[Name],[Description],[Contracted_by],[Vendor_Name],[Related_Dept]," + 
     "[Start_date],[Expiration_Date],[TypeofContract],[Contact_Person]," + 
     "[Contact_No],FileName,FileData,FileType) VALUES (" + 
     "@cid, @name, @desc, @cby, @vname, @rdept, @stdate, @expdate, " + 
     "@tc, @cp, @cno, @file, @fdate, @ftype",con)

  SqlParameter p = new SqlParameter("@cid", SqlDbType.Int).Value = Convert.ToInt32(textBox1.Text));
  cmd.Parameters.Add(p);
  .... and so on for the other parameters required

By the way, remember that if you have an IDENTITY column you should not try to insert anything in that column (Contract_ID is particulary suspect here)

solved SQL server remove space before value when I insert data