I have a piece of code that takes two strings, puts them together, then attempts to save that result into a table in a database. For some reason, the database is only showing the second half of the string ( Me.txtRev.text in this case). When in debug, I can see that newRev is actually correct, with the hyphenated string.

Any ideas anyone? Thanks in advance!

Dim newRev As String = Me.revs(0) & "-" & Me.txtRev.Text

Try
   Dim sqlSOPDept As New SqlClient.SqlCommand
   Dim sqlConn As New SqlClient.SqlConnection("Data Source=IMS-SQL-01;Initial Catalog=ImageTraining;Integrated Security=True")
   sqlSOPDept.CommandText = "UPDATE dbo.docHeader SET revision =" & newRev & " WHERE model = '" & Me.cmbModel.SelectedValue.ToString & "' AND part = '" & Me.cmbPart.SelectedValue.ToString & "'"
   sqlSOPDept.CommandType = CommandType.Text
   sqlSOPDept.Connection = sqlConn
   sqlConn.Open()

   sqlSOPDept.ExecuteNonQuery()

   sqlConn.Close()
Catch ex As Exception
   MsgBox(ex.ToString)
End Try

Your error is in the Update query. You mixed up one and double quotes. Do it this way:

sqlSOPDept.CommandText = "UPDATE dbo.docHeader SET revision = '" & newRev & "' WHERE model = '" & Convert.ToString(Me.cmbModel.SelectedValue.ToString) & "' AND part = '" & Convert.ToString(Me.cmbPart.SelectedValue.ToString) & "'"

Sometimes it just takes another pair of eyes. Thank you very much. Works like a charm!

This question has already been answered. Start a new discussion instead.