[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DisplayMember error on combobox in vb.net 2005

Posted on 2007-08-01
7
Medium Priority
?
265 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:ljhodgett
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 19607280
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
 

Author Comment

by:ljhodgett
ID: 19607351
Hi,

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

Regards
Lee
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 19607366
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ljhodgett
ID: 19607393
Hi,

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

Best Regards
Lee
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19607646
Depending of the database you are using it will be SSDNumber + " " & Description as SSDNumber_Descrip
or SSDNumber & " " &  Description as SSDNumber_Descrip
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19607653
So try to change you sql-statement:
(probably & instead of +)
0
 

Author Comment

by:ljhodgett
ID: 19607723
there was a comma missing after PartIdentify.

Many Thanks for your help.
Lee
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question