title: How to solve the "String or binary data would be truncated.\r\nThe statement has been terminated." error?
body: <p>I have a procedure which updates some records. When I execute it I get the following exception        </p>
  
  <blockquote>
    <p>"String or binary data would be truncated.\r\nThe statement has been terminated."         </p>
  </blockquote>
  
  <p>I could found this occur when the parameter length is larger than variable's length. I checked again changing the size. But didn't work. Go the same exception again. How can I solve this? Please help         </p>
  
  <p>Here is my code for update      </p>
  
  <pre><code>            bool isFinished = dba.update(desingnation, title, initials, surname, fullname, callingName, civilSatatus, natinality, nic, birthday, passport,
                                            hometp, mobiletp, province, district, division, electorate, gramaNiladhari, takafull, p_city,
                                            c_city, p_hno, c_hno, tokens_P, tokens_C, previousEmployeements, bank, branch, type, account, gender, educatinalQ, languageE, languageS, languageT, empNo, appNo);
              if (isFinished)
              {
                  WebMsgBox.Show("Successfully Inserted!");
              }
              else
              {
                  WebMsgBox.Show("Some Errors Occured");
              }
          }
          else
          {
              WebMsgBox.Show("Some feilds are not valid");
          }
      }
  }              
  </code></pre>
  
  <p>This is the code for passing parameters to stored procedures         </p>
  
  <pre><code>            try
              {
                  using (SqlCommand cmd = new SqlCommand())
                  {
                      cmd.CommandType = CommandType.Text;
                      cmd.CommandType = CommandType.StoredProcedure;
                      cmd.Connection = connection;
                      cmd.CommandTimeout = 0;
                      cmd.Transaction = transactions;
  
                      /*=======================Update employee details================================*/
                      cmd.CommandText = "update_HS_HR_EMPLOYEE_AADM";
  
                      cmd.Parameters.Add("@appNo", SqlDbType.Int).Value = appNo;
                      cmd.Parameters.Add("@CALLING_NAME", SqlDbType.VarChar).Value = callingName;
                      cmd.Parameters.Add("@INITIALS", SqlDbType.VarChar).Value = initials;
                      cmd.Parameters.Add("@SURNAME", SqlDbType.VarChar).Value = surname;
                      cmd.Parameters.Add("@TITLE", SqlDbType.VarChar).Value = title;
                      cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = fullname;
                      cmd.Parameters.Add("@FULLNAME", SqlDbType.VarChar).Value = fullname + " " + surname;
                      cmd.Parameters.Add("@NIC", SqlDbType.VarChar).Value = nic;
                      cmd.Parameters.Add("@BDY", SqlDbType.VarChar).Value = birthday;
                      cmd.Parameters.Add("@GENDER", SqlDbType.VarChar).Value = gender;
                      cmd.Parameters.Add("@NATIONALITY", SqlDbType.VarChar).Value = natinality;
                      cmd.Parameters.Add("@CIVILSTATUS", SqlDbType.VarChar).Value = civilSatatus;
                      cmd.Parameters.Add("@DESIGNATION", SqlDbType.VarChar).Value = desingnation;
                      cmd.Parameters.Add("@P_ADD1", SqlDbType.VarChar).Value = p_hno;
                      cmd.Parameters.Add("@P_ADD2", SqlDbType.VarChar).Value = tokens_P[0];
  
                      if (tokens_P.Length &gt; 1)
                          cmd.Parameters.Add("@P_ADD3", SqlDbType.VarChar).Value = tokens_P[1];
                      else
                          cmd.Parameters.Add("@P_ADD3", SqlDbType.VarChar).Value = "";
  
                      cmd.Parameters.Add("@P_CITY", SqlDbType.VarChar).Value = p_city;
                      cmd.Parameters.Add("@TP_HOME", SqlDbType.VarChar).Value = hometp;
                      cmd.Parameters.Add("@TP_MOBILE", SqlDbType.VarChar).Value = mobiletp;
                      cmd.Parameters.Add("@PROVINCE", SqlDbType.VarChar).Value = province;
                      cmd.Parameters.Add("@DISTRICT", SqlDbType.VarChar).Value = district;
                      cmd.Parameters.Add("@C_ADD1", SqlDbType.VarChar).Value = c_hno;
                      cmd.Parameters.Add("@C_ADD2", SqlDbType.VarChar).Value = tokens_C[0];
                      cmd.Parameters.Add("@PER_GNDIV_CODE", SqlDbType.VarChar).Value = gramaNiladhari;
                      cmd.Parameters.Add("@PER_DSDIV_CODE", SqlDbType.VarChar).Value = division;
                      cmd.Parameters.Add("@TAKAFUL", SqlDbType.VarChar).Value = takafull;
                      cmd.Parameters.Add("@PASSPORT_NO", SqlDbType.VarChar).Value = passport;
  
                      if (tokens_C.Length &gt; 1)
                          cmd.Parameters.Add("@C_ADD3", SqlDbType.VarChar).Value = tokens_C[1];
                      else
                          cmd.Parameters.Add("@C_ADD3", SqlDbType.VarChar).Value = "";
  
                      cmd.Parameters.Add("@C_CITY", SqlDbType.VarChar).Value = c_city;
                      cmd.Parameters.Add("@ELECTORATE", SqlDbType.VarChar).Value = electorate;
  
                      //int appNO = int.Parse((cmd.ExecuteScalar().ToString()));
                      cmd.ExecuteNonQuery();
                      cmd.Parameters.Clear();         
  
  
    }     
  }         
  </code></pre>
  
  <p>This is the stored procedure           </p>
  
  <pre><code>ALTER PROCEDURE [dbo].[update_HS_HR_EMPLOYEE_AADM] 
  @appNo Int,
  @CALLING_NAME VARCHAR(50),
  @INITIALS VARCHAR(50),
  @SURNAME VARCHAR(50),
  @TITLE VARCHAR(50),
  @NAME VARCHAR(50),
  @FULLNAME VARCHAR(100),
  @NIC VARCHAR(15),
  @BDY VARCHAR(50),
  @GENDER CHAR(1),
  @NATIONALITY VARCHAR(50),
  @CIVILSTATUS VARCHAR(50),
  @DESIGNATION VARCHAR(50),
  @P_ADD1 VARCHAR(50),
  @P_ADD2 VARCHAR(50),
  @P_ADD3 VARCHAR(50),
  @P_CITY VARCHAR(50),
  @TP_HOME VARCHAR(50),
  @TP_MOBILE VARCHAR(50),
  @PROVINCE VARCHAR(50),
  @DISTRICT VARCHAR(50),
  @C_ADD1 VARCHAR(50),
  @C_ADD2 VARCHAR(50),
  @C_ADD3 VARCHAR(50),
  @C_CITY VARCHAR(50),
  @ELECTORATE VARCHAR(50),
  @PER_GNDIV_CODE VARCHAR(50),
  @PER_DSDIV_CODE VARCHAR(50),
  @TAKAFUL VARCHAR(50),
  @PASSPORT_NO VARCHAR(50)
  
  AS
  
  BEGIN
  
  update [HS_HR_EMPLOYEE_AADM]
  SET
         [EMP_CALLING_NAME]=@CALLING_NAME
         ,[EMP_MIDDLE_INI]=@INITIALS
         ,[EMP_SURNAME]=@SURNAME
         ,[EMP_TITLE]=@TITLE
         ,[EMP_NAMES_BY_INI]=@NAME
         ,[EMP_FULLNAME]=@FULLNAME
         ,[EMP_NIC_NO]=@NIC
         ,[EMP_BIRTHDAY]=@BDY
         ,[EMP_GENDER]=@GENDER
         ,[NAT_CODE]=@NATIONALITY
         ,[EMP_MARITAL_STATUS]=@CIVILSTATUS
         ,[EMP_DATE_JOINED]=GETDATE()
         ,[EMP_CONFIRM_FLG]=0
         ,[CT_CODE]='000008'
         ,[DSG_CODE]=@DESIGNATION
         ,[CAT_CODE]='000001'
         ,[EMP_PER_ADDRESS1]=@P_ADD1
         ,[EMP_PER_ADDRESS2]=@P_ADD2
         ,[EMP_PER_ADDRESS3]=@P_ADD3
         ,[EMP_PER_CITY]=@P_CITY
         ,[EMP_PER_TELEPHONE]=@TP_HOME
         ,[EMP_PER_MOBILE]=@TP_MOBILE
         ,[EMP_PER_PROVINCE_CODE]=@PROVINCE
         ,[EMP_PER_DISTRICT_CODE]=@DISTRICT
         ,[EMP_TEM_ADDRESS1]=@C_ADD1
         ,[EMP_TEM_ADDRESS2]=@C_ADD2
         ,[EMP_PER_ELECTORATE_CODE]=@ELECTORATE
         ,[EMP_TEM_ADDRESS3]=@C_ADD3
         ,[EMP_TEM_CITY]=@C_CITY
         ,[EMP_PER_GNDIV_CODE]=@PER_GNDIV_CODE
         ,[EMP_PER_DSDIV_CODE]=@PER_DSDIV_CODE
         ,[EMP_PASSPORT_NO]=@TAKAFUL
         ,[EMP_TAK]=@PASSPORT_NO
         where App_no = @appNo
  
  END
  </code></pre>