Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is my select SQL syntax to display the category choices, but what I need to do is display the corresponding category chosen based on equipment_id

I got 2 tables, tblOfficeEquipmentCategory and tblOfficeEquipmentProfile

I need to inner join tblOfficeEquipmentProfile so I can add the WHERE equipment_id = '"txtid.text"'

What would be the corresponding SQL syntax

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 SqlCommand

    sqlconn.Open()
    Dim da As New SqlDataAdapter("select * from tblOfficeEquipmentCategory", sqlconn)
    Dim dt As New DataTable
    da.Fill(dt)
    cmbCategory.DataSource = dt
    cmbCategory.ValueMember = "CAT_Name"
    cmbCategory.DisplayMember = "CAT_ID"
    sqlconn.Close()
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
225 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming equipment_id is located on table tblOfficeEquipmentProfile and a column CAT_ID which links it to table tblOfficeEquipmentCategory.

SELECT  a.CAT_Name
FROM    tblOfficeEquipmentCategory a
        INNER JOIN tblOfficeEquipmentProfile b
            ON a.CAT_ID = b.CAT_ID
WHERE   b.equipment_id = @ID

To further gain more knowledge about joins, kindly visit the link below:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...