title: C# & SQL Server : incomplete update (string type)
body: <p>I'm trying to update a column with a string and it doesn't update correctly. </p>
  
  <p>I'm displaying the <code>string</code> right before the update function and even after it's passed as a parameter (<code>tip_reparatii</code>,from the function) it's the same string but it doesn't update in the database.</p>
  
  <p>The update function:</p>
  
  <pre><code>public void updateInventar ( int ID_INVENTAR, int ID_CEAS, DateTime data_intrare, string tip_reparatii, string pret, int tip_contact1, int ok_refuse, int tip_contact2, DateTime ok_refuse_date, int ID_STATUS, int ID_LOCALIZARE, DateTime data_iesire, string note, int ID_TEHNICIAN ) {
      if ( IsOnline() ) {
          try {
              string sqlInsertQuery = "UPDATE dbo.Inventar SET data_intrare=@data_intrare, tip_reparatii=@tip_reparatii, pret=@pret, tip_contact1=@tip_contact1, ok_refuse=@ok_refuse, tip_contact2=@tip_contact2, ok_refuse_date=@ok_refuse_date, ID_STATUS=@ID_STATUS, ID_LOCALIZARE=@ID_LOCALIZARE, data_iesire=@data_iesire, note=@note,ID_TEHNICIAN=@ID_TEHNICIAN WHERE ID_INVENTAR=@ID_INVENTAR AND ID_CEAS=@ID_CEAS";
              SqlCommand cmd = new SqlCommand(sqlInsertQuery, DbCon);
              MessageBox.Show(tip_reparatii); //this is the same string and it's correct
  
              cmd.Parameters.AddWithValue("@data_intrare", data_intrare);
              cmd.Parameters.AddWithValue("@tip_reparatii", tip_reparatii);
              cmd.Parameters.AddWithValue("@pret", pret);
              cmd.Parameters.AddWithValue("@tip_contact1", tip_contact1);
              cmd.Parameters.AddWithValue("@ok_refuse", ok_refuse);
              cmd.Parameters.AddWithValue("@tip_contact2", tip_contact2);
              cmd.Parameters.AddWithValue("@ok_refuse_date", ok_refuse_date);
              cmd.Parameters.AddWithValue("@ID_STATUS", ID_STATUS);
              cmd.Parameters.AddWithValue("@ID_LOCALIZARE", ID_LOCALIZARE);
              cmd.Parameters.AddWithValue("@data_iesire", data_iesire);
              cmd.Parameters.AddWithValue("@note", note);
              cmd.Parameters.AddWithValue("@ID_TEHNICIAN", ID_TEHNICIAN);
              cmd.Parameters.AddWithValue("@ID_INVENTAR", ID_INVENTAR);
              cmd.Parameters.AddWithValue("@ID_CEAS", ID_CEAS);
  
              cmd.ExecuteNonQuery();
          } catch ( SqlException e ) {
              MessageBox.Show(null, "Could not Update! " + e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      } else {
          MessageBox.Show(null, "SQL Connection Throttled!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
  }
  </code></pre>
  
  <p>The call code:</p>
  
  <pre><code>private void btnActualiser_Click(object sender, EventArgs e)
  {
      string tipReparatiiString = "";
  
      if (this.cblReparatii.CheckedItems.Count &gt; 0)
      {
          foreach (DataRowView itm in cblReparatii.CheckedItems)
          {  
              tipReparatiiString += itm.Row.ItemArray[0].ToString() + " ";
          }
  
          MessageBox.Show(tipReparatiiString); //this is correct
          obj.updateInventar(int.Parse(this.cblReparatii.SelectedValue.ToString()), int.Parse(this.cbCeas.SelectedValue.ToString()), this.dtDataIn.Value, tipReparatiiString, this.tbPrix.Text, this.cbPrin.SelectedIndex, this.cbOkRef.SelectedIndex, this.cbPrin2.SelectedIndex, this.dtOkRef.Value, int.Parse(this.cbStatus.SelectedValue.ToString()), int.Parse(this.cbLocatie.SelectedValue.ToString()), this.dtDataOut.Value, this.tbNote.Text, int.Parse(this.cbTehnician.SelectedValue.ToString()));
  
      }
      else
      {
          //Msg 
      }      
  }
  </code></pre>
  
  <p>Both message boxes display the correct string but it doesn't update in the database or it sometimes updates incorrectly(a piece of the string).  </p>
  
  <p>We added a <code>string</code> manually as a parameter and it worked:</p>
  
  <pre><code>obj.updateInventar(int.Parse(this.cblReparatii.SelectedValue.ToString()), 
                     int.Parse(this.cbCeas.SelectedValue.ToString()), 
                     this.dtDataIn.Value, "this works perfectly", 
                     this.tbPrix.Text, this.cbPrin.SelectedIndex, 
                     this.cbOkRef.SelectedIndex, this.cbPrin2.SelectedIndex, 
                     this.dtOkRef.Value, 
                     int.Parse(this.cbStatus.SelectedValue.ToString()),  
                     int.Parse(this.cbLocatie.SelectedValue.ToString()), 
                     this.dtDataOut.Value, this.tbNote.Text, 
                     int.Parse(this.cbTehnician.SelectedValue.ToString()) );  
  </code></pre>
  
  <p>The other values update correctly.</p>