Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET
Because I have 6 CheckedListBox and whenever I select items from 4 CheckedListBoxes only, an error pops up but it still filters.
 
*UPDATED
(For every CheckedBoxList, this is the code that I use but with different variable names)
And also is there a way to make multiple data into one? Example is, when I input John in Client 4x, it would show John(x4) in the CheckedListBox. But the goal is to filter.. Is there a way to make John appear once?
 

  Dim dt1 As DataTable
        Dim ds1 As New DataSet
        cnn = New OleDbConnection(connectionString)
        Dim clientList As String = "("
        For item1 As Integer = 0 To CheckedListBox2.CheckedItems.Count - 1
            clientList += "'" & CheckedListBox2.CheckedItems(item1) & "',"
        Next
        clientList = clientList.Substring(0, clientList.Length - 1) + ")"
 
        Dim sql1 = "select * from NTIdb where Client in " + clientList
 
        Try
            cnn.Open()
            adptr = New OleDbDataAdapter(sql1, cnn)
            adptr.Fill(ds1)
            adptr.Dispose()
            cnn.Close()
 
            dt1 = ds1.Tables(0)
            Form5.DataGridView1.DataSource = dt1
 
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Form5.DataGridView1.Visible = True
Posted 10-Mar-13 17:57pm
PBubble129
Edited 10-Mar-13 19:09pm
v3
Comments
Sergey Alexandrovich Kryukov at 10-Mar-13 23:46pm
   
Not clear. What error? Do you mean exception? Please, full exception information, but also show some code sample.
—SA
PBubble at 11-Mar-13 0:11am
   
Updated the question! And the error that appears is "In operator without () in query expression" but someone told me it's because I did not check a box from one of the CheckedListBox that's why I get that error.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Maybe you can use distinct in your SQL statement. For example:
Dim sql1 = "select distinct from NTIdb where Client in " + clientList
  Permalink  
Comments
PBubble at 11-Mar-13 10:51am
   
Nope it still says the same error.

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

  Print Answers RSS
0 OriginalGriff 459
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 11 Mar 2013
Copyright © CodeProject, 1999-2014
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