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
ljhodgettAsked:
Who is Participating?
 
DhaestCommented:
The easiest solution will be to concatenate the fields in your query...

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

cmbRigs.DisplayMember = "SSDNumber_Description"
0
 
DhaestCommented:
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"
0
 
ljhodgettAuthor Commented:
Hi,

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

Regards
Lee
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ljhodgettAuthor Commented:
Hi,

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

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

Many Thanks for your help.
Lee
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.