简体   繁体   中英

Populating combo box from SQL database records

For now, I have this code but it is neither working nor returning errors.

How would I get all the records in the database to display it in the combo box?

Private Sub cmbCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCategory.Click
    Dim sqlconn As New SqlClient.SqlConnection
    sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
    "Database = EOEMS;integrated security=true"

    Dim myCommand As New SqlCommand
    sqlconn.Open()
    myCommand = New SqlCommand("SELECT CAT_ID FROM tblOfficeEquipmentCategory)", sqlconn)
    myCommand.ExecuteNonQuery()
    sqlconn.Close()
End Sub

Please put your select statement to a query browser and RUN it BEFORE telling your code is having any problem. This should be a MUST DO practice when dealing with database related web programming.

It is obvious that there is an extra ")" in your SQL statement.

You have an extra bracket, try this:

myCommand = New SqlCommand("SELECT CAT_ID FROM tblOfficeEquipmentCategory", sqlconn)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM