Good evening!

I'm trying to figure out how to retrieve and display data from MS Access to my project's DataGridView. So far I have the codes to make the options for the CheckedListBox appear.

SAMPLE:
(Codes for other categories are not included since they're all basically the same)

'view client items
        connectionString = "provider=microsoft.jet.oledb.4.0;data source=|datadirectory|\invdata.mdb;"

        Dim ds1 As New DataSet
        Dim sql1 As String = "select Client from NTIdb"
        'dim dif as integer
        cnn = New OleDbConnection(connectionString)

        Try
            cnn.Open()
            adptr = New OleDbDataAdapter(sql1, cnn)
            adptr.Fill(ds1)

            For a = 0 To ds1.Tables(0).Rows.Count - 1
                CheckedListBox2.Items.Add(ds1.Tables(0).Rows(a).Item(0))
            Next

            adptr.Dispose()
            cnn.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

And it would look like this:
http://i.imgur.com/aYq9nUm.png

What I want to achieve is to have the user check from the options (e.g Demo + Uru +Akai, etc..) from each categories (e.g Client, Status, Brand, etc..) and have it display on a DataGridView once the Filter button is clicked.

The other problem is the duplication of options. When the user adds multiple entries with the same value (from my Data Entry form which I did not include here), the same value appears in the CheckedListBox and I want to avoid that. I've been trying out stuffs but it doesn't seem to work.

Are my problems even possible to meet a solution? Or do you guys have any idea how to make it work?

Recommended Answers

All 5 Replies

What I want to achieve is to have the user check from the options (e.g Demo + Uru +Akai, etc..) from each categories (e.g Client, Status, Brand, etc..) and have it display on a DataGridView once the Filter button is clicked.

build your query using one of the Selected properties of each checkedlistbox. Not sure which would work better index, item, value.

The other problem is the duplication of options. When the user adds multiple entries with the same value (from my Data Entry form which I did not include here), the same value appears in the CheckedListBox and I want to avoid that. I've been trying out stuffs but it doesn't seem to work.

Have you tried the CheckedListBox1.Items.Contains method before you add each item?

So I did this for the first problem:

'For Status
        Dim sb As New System.Text.StringBuilder
        For item As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
            Dim sql = "select * from Status where Stat= " & CheckedListBox1.SelectedItem() & ""
            Dim dt As DataTable
            Dim ds As New DataSet
            cnn = New OleDbConnection(connectionString)

            Try
                cnn.Open()
                adptr = New OleDbDataAdapter(sql, cnn)
                adptr.Fill(ds)
                adptr.Dispose()
                cnn.Close()

                dt = ds.Tables(0)
                Form5.DataGridView1.DataSource = dt

            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Form5.DataGridView1.Visible = True
        Next

And I got the "No value given for one or more required paramaters." errror

try this, Dim sql = "select * from Status where Stat= " & CheckedListBox1.CheckedItems(item).ToString & "".

Unfortunately it still says the "No value given..." error :(

Set a break point and see if CheckedListBox1.CheckedItems(item).ToString has the value you expect. If so maybe your query string isn't set up right.

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.