First i am loving this forum, it has been very helpful and learnt a fair bit going through past posts.

But i am here again after several hours of trying to work this outi thought i better ask the professionals.

Basially i would like to do the following:

1) Query my SQL DB and look at the selected supplier from my combobox locate the SupplierID from the selected supplier.
2) Update the DB fields for the selected supplier using the SQL Update command using the supplierID as main field.

I beleive the error is relating to that the supplier is a integer and my lookup from the combo box is a string.

In my code i have tried to convert the string to a integer but its not working or am i looking in the worng place.

    Private Sub btnupdate_Click(sender As Object, e As EventArgs) Handles btnupdate.Click
        Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=JAMESPC\SUPPORTDB;Initial Catalog=Support_DB;Persist Security Info=True;User ID=username;Password=password")
        Dim SQLcmd As SqlCommand
        Dim SupID As SqlCommand
        Dim result As Integer
        Dim SupIDResult As String = "Select SupplierID from Suppliers where SupplierName = '" & ComboBox1.Text & "'"
        Dim QueryOpen As String = "update suppliers set PhoneNumber ='" & PhoneNumberTextBox.Text & "' Notes ='" & NotesTextBox.Text & "' where SupplierID = '" & result & "'"

            SupID = New SqlCommand(SupIDResult, Sqlcon)
            SQLcmd = New SqlCommand(QueryOpen, Sqlcon)
            result = Convert.ToInt32(SupID.ExecuteScalar())
            'This is for testing so i can see it is the correct supplier ID ref against the SQLStudio lookup.
            MessageBox.Show("The ID is " & result, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
            MessageBox.Show("The supplier" & " " & ComboBox1.Text & " " & "has been updated.", "Supplier Created", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MsgBox("Error while editing the suppliers record..." & " " & ex.Message, "Update Error", MessageBoxIcon.Exclamation)
        End Try

    End Sub

Name:  update error.JPG
Views: 142
Size:  23.2 KB

I am also tring to work out trying to use SQL Parameters as i think this may help?

Thanks Once Again.