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,Jo bReference ,RoutingSt age,bPCBTe ster,bDriv eTester, bObsolete, PartIdentity FROM Admin_SSDNumber WHERE bLogicalDelete=0 ORDER BY SSDNumber;"
dbOpen2()
Dim da As New SqlClient.SqlDataAdapter(s ql, 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
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
dbOpen2()
Dim da As New SqlClient.SqlDataAdapter(s
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
ASKER
Hi,
No, It works correctly when it's just cmbRigs.DisplayMember = "SSDNumber"
Regards
Lee
No, It works correctly when it's just cmbRigs.DisplayMember = "SSDNumber"
Regards
Lee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
It comes up incorrect syntax near '+' in the sql statement.
Best Regards
Lee
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
or SSDNumber & " " & Description as SSDNumber_Descrip
So try to change you sql-statement:
(probably & instead of +)
(probably & instead of +)
ASKER
there was a comma missing after PartIdentify.
Many Thanks for your help.
Lee
Many Thanks for your help.
Lee
cmbRigs.DataSource = ds.Tables("Rigs")
cmbRigs.DisplayMember = "SSDNumber"
cmbRigs.ValueMember = "Description"