Click here to Skip to main content
12,623,903 members (27,469 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
I am trying to filter using CheckedListBox, and so far it always gives me the "No Value Given" error when I have these codes:

For item As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
           Dim sql = "select * from Status where Stat= " & CheckedListBox1.CheckedItems(item).ToString() & ""
           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

I'm pretty sure my Access tables are named correctly..
Posted 22-Feb-13 1:52am
PBubble129
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You probably need to wrap single quotes around the variable that you are substituting in:

Dim sql = "select * from Status where Stat= '" & CheckedListBox1.CheckedItems(item).ToString() & "'"
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

It works! Thank you very much :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100