ivandinglasan
ivandinglasan

Reputation: 384

sql where clause in vb.net

This is my working sql syntax using sql query analyzer, it display the record i wanted

SELECT     OE_Category, OE_ID
FROM         tblOfficeEquipmentProfile
WHERE     (OE_ID = 'dxdxdx')

Upon using it to vb.net:

 Public Sub DisplayCategory()
    'based on oe_id'
    Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
    "Database = EOEMS;integrated security=true"

    Dim sqlcommand As New SqlCommand

    sqlconn.Open()
    Dim da As New SqlDataAdapter("SELECT OE_Category, OE_ID FROM tblOfficeEquipmentProfile WHERE OE_ID = '" & txtOEID.Text & "'", sqlconn)
    Dim dt As New DataTable
    da.Fill(dt)
    cmbCategory.DataSource = dt
    cmbCategory.ValueMember = "CAT_ID"
    cmbCategory.DisplayMember = "CAT_Name"
    sqlconn.Close()
End Sub

An error occured:

Could not bind to the new display member.

Upvotes: 1

Views: 2702

Answers (1)

DavidB
DavidB

Reputation: 2596

Your selecting OE_Category, OE_ID and binding CAT_ID and CAT_Name

try instead:

cmbCategory.ValueMember = "OE_ID"
cmbCategory.DisplayMember = "OE_Category"

You also dont bind the control

Upvotes: 5

Related Questions