Link to home
Start Free TrialLog in
Avatar of ljhodgett
ljhodgett

asked on

DisplayMember error on combobox in vb.net 2005

Hi,

I currently have quote a large project for my first really program writen in vb.net and am finding there are a lot of things I need to know to accomplish this so I would apprecitate your help as a novice.

I have the following code: -

    Private Sub frmAddProduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        On Error GoTo error_Handler

        Dim ds As New DataSet

        sql = "SET NOCOUNT ON; SELECT TestRigID,SSDNumber, Description,CalibrationDue,bUserLock,DocNum,JobReference,RoutingStage,bPCBTester,bDriveTester, bObsolete, PartIdentity FROM Admin_SSDNumber WHERE bLogicalDelete=0 ORDER BY SSDNumber;"

        dbOpen2()
        Dim da As New SqlClient.SqlDataAdapter(sql, oConn)
        da.Fill(ds, "Rigs") ' populate data set "da" with the data returned from sql command "ds" and set dataset name to "Rigs"
        DataGridView1.DataSource = ds.Tables("Rigs")

        cmbRigs.DisplayMember = ("SSDNumber" & "-" & "Description")
        cmbRigs.ValueMember = "Description"
        cmbRigs.DataSource = ds.Tables("Rigs")

error_Handler:
        If Err.Number <> 0 Then
            MsgBox("An error has occured while connecting to the SQL Server. Error no: " & Err.Number & vbCrLf & vbCrLf & "Description:" & vbCrLf & Err.Description)
            dbClose()
            End
        End If

        dbClose2()

    End Sub

Where I set the cmbRigs.DisplayMember = ("SSDNumber" & "-" & "Description") it only shows System.Data.DataRowView as the data in the combobox. IT was originally SSDNumber and it worked correctly but I need it to show the SSDNumber and then the Description at the side on the same line of the combobox.

Is this at all possible?

Best Regards
Lee
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

If you try it with only one field (just testing). Do you still get "system.data...." ?
        cmbRigs.DataSource = ds.Tables("Rigs")
       cmbRigs.DisplayMember = "SSDNumber"
        cmbRigs.ValueMember = "Description"
Avatar of ljhodgett
ljhodgett

ASKER

Hi,

No, It works correctly when it's just cmbRigs.DisplayMember = "SSDNumber"

Regards
Lee
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

It comes up incorrect syntax near '+' in the sql statement.

Best Regards
Lee
Depending of the database you are using it will be SSDNumber + " " & Description as SSDNumber_Descrip
or SSDNumber & " " &  Description as SSDNumber_Descrip
So try to change you sql-statement:
(probably & instead of +)
there was a comma missing after PartIdentify.

Many Thanks for your help.
Lee