Hi to everyone, i am trying to display certain data onto some labels depending on the selection the user does from a combobox.
The database consists of two tables, RegisterShipment and Shipments, where the RegisterShipmentID is linked to the Shipment Table by a Foreign Key.
On the form i have a combobox and 4 labels, were the comboBox is loaded from the RegShipment table with the following Code

 dvShipmentNo.Table = mySQL.LoadRegister()

        cboShipmentNo.DataSource = dvShipmentNo
        cboShipmentNo.DisplayMember = "ConsignmentNo"
        cboShipmentNo.ValueMember = "RegShipmentID"

The following Code is what i am using from the Combobox event to display the data in the labels

 Private Sub cboShipmentNo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboShipmentNo.SelectedIndexChanged
            Dim Query As String
            Query = "Select ContainerNo, TotalGrossWeight, TotalCartons, TotalPieces From Shipments Where RegShipmentID = '" & cboShipmentNo.SelectedValue & "'"

            Dim fill As New DataSet
            fill = ObjSQLQuery.PopDataSet(Query)
            If fill.Tables(0).Rows.Count >= 1 Then
                lblContainerNo.Text = fill.Tables(0).Rows(0)("ContainerNo").ToString
                lblGrossWeight.Text = fill.Tables(0).Rows(0)("TotalGrossWeight").ToString
                lblTotalColli.Text = fill.Tables(0).Rows(0)("TotalCartons").ToString
                LblTotalPieces.Text = fill.Tables(0).Rows(0)("TotalPieces").ToString
            End If

        Catch ex As Exception
            MessageBox.Show("Details Could not Be Loaded" & ex.Message, ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    End Sub

When i run the above code nothing is displayed on the labels, and through debugging it is giving the error that the 'Operator '&' is not defined for string "Select ContainerNo, TotalGrossWe" and type 'DataRowView'.
Can someone tell me what i am doing wrong, it may be the Select statment chosen that i may be using which is not correct. Any help will be appreciated.

Recommended Answers

All 2 Replies

Try using the ToString() method:

Query = "Select ContainerNo, TotalGrossWeight, TotalCartons, TotalPieces From Shipments Where RegShipmentID = '" & cboShipmentNo.SelectedValue.ToString() & "'"

Thanks tinstaafl will give it a try and let you know if all ok or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.