I have a program that I'm building and I have a form load event that loads the data from a table, but when I try and load the data from a query I get an error. Here is my code:

MyTable = MyDa.GetData()
If MyTable.Rows.Count > 0 Then
Dim MyRow As dsCM2008.tblSoftwareRow = CType(MyTable.Rows(0), dsCM2008.tblSoftwareRow)
ShowData(MyRow)

End If
Try
Catch ex As Exception

End Try

There is in the ShowData(MyRow). Since the query uses a Like "TypeOfSoftware" in the tblSoftware table, i.e. "AntiVirus", "AntiSpam", "Firewall", "Operating System" etc, I'm not getting the data loading from the query. Any help would be greatly appreciated.

Also, does anyone know how to bind a combobox with code to a table or query?

this code i used to bind data into combobox :

Private Sub ReadData()
        Dim i As Integer
        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        Dim dtStudent As New DataTable
        Dim conn As SqlConnection

        conn = GetConnect()
        Try

            cmdStudent = conn.CreateCommand
            cmdStudent.CommandText = "SELECT * FROM Student"
            daStudent.SelectCommand = cmdStudent
            daStudent.Fill(dsStudent, "Student")
            dtStudent = dsStudent.Tables("Student")
            For i = 0 To dtStudent.Rows.Count - 1
                cmbNis.Items.Add(dtStudent.Rows(i).Item(0)) ' fill into combobox
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try
        conn.Close()
    End Sub

this code i used to bind data into combobox :

Private Sub ReadData()
        Dim i As Integer
        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        Dim dtStudent As New DataTable
        Dim conn As SqlConnection

        conn = GetConnect()
        Try

            cmdStudent = conn.CreateCommand
            cmdStudent.CommandText = "SELECT * FROM Student"
            daStudent.SelectCommand = cmdStudent
            daStudent.Fill(dsStudent, "Student")
            dtStudent = dsStudent.Tables("Student")
            For i = 0 To dtStudent.Rows.Count - 1
                cmbNis.Items.Add(dtStudent.Rows(i).Item(0)) ' fill into combobox
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try
        conn.Close()
    End Sub

I asked about MS Access, not MS SQL

sorry i don't read carefully..:)
i think that has a same logic :
the point of my code is in this following code :

For i = 0 To dtStudent.Rows.Count - 1
    cmbNis.Items.Add(dtStudent.Rows(i).Item(0)) ' fill into combobox
Next

you can implement in your access code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.