本文介绍了过滤按钮错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我总是在使用这些代码时出现错误在查询表达式中没有()的操作符:
(当我将其他所有内容写入注释但是当我启用时,它适用于状态和客户端我收到错误的一切)
I always get the error "In operator without () in query expression" using these codes:
(It works fine for Status and Client when I made everything else into a comment but when I enabled everything I get the error)
'For Status
Dim dt As DataTable
Dim ds As New DataSet
cnn = New OleDbConnection(connectionString)
Dim statList As String = "("
For item As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
statList += "'" & CheckedListBox1.CheckedItems(item) & "',"
Next
statList = statList.Substring(0, statList.Length - 1) + ")"
Dim sql = "select * from Status where Stat in " + statList
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
'For Client
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
'For Usage
Dim dt2 As DataTable
Dim ds2 As New DataSet
cnn = New OleDbConnection(connectionString)
Dim usageList As String = "("
For item2 As Integer = 0 To CheckedListBox3.CheckedItems.Count - 1
usageList += "'" & CheckedListBox3.CheckedItems(item2) & "',"
Next
usageList = usageList.Substring(0, usageList.Length - 1) + ")"
Dim sql2 = "select * from NTIdb where ProdUsage in " + usageList
Try
cnn.Open()
adptr = New OleDbDataAdapter(sql2, cnn)
adptr.Fill(ds2)
adptr.Dispose()
cnn.Close()
dt2 = ds2.Tables(0)
Form5.DataGridView1.DataSource = dt2
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Form5.DataGridView1.Visible = True
'For Product Category
Dim dt3 As DataTable
Dim ds3 As New DataSet
cnn = New OleDbConnection(connectionString)
Dim categoryList As String = "("
For item3 As Integer = 0 To CheckedListBox4.CheckedItems.Count - 1
categoryList += "'" & CheckedListBox4.CheckedItems(item3) & "',"
Next
categoryList = categoryList.Substring(0, categoryList.Length - 1) + ")"
Dim sql3 = "select * from NTIdb where ProdCategory in " + categoryList
Try
cnn.Open()
adptr = New OleDbDataAdapter(sql3, cnn)
adptr.Fill(ds3)
adptr.Dispose()
cnn.Close()
dt3 = ds3.Tables(0)
Form5.DataGridView1.DataSource = dt3
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Form5.DataGridView1.Visible = True
'For Brand
Dim dt4 As DataTable
Dim ds4 As New DataSet
cnn = New OleDbConnection(connectionString)
Dim brandList As String = "("
For item4 As Integer = 0 To CheckedListBox5.CheckedItems.Count - 1
brandList += "'" & CheckedListBox5.CheckedItems(item4) & "',"
Next
brandList = brandList.Substring(0, brandList.Length - 1) + ")"
Dim sql4 = "select * from NTIdb where Brand in " + brandList
Try
cnn.Open()
adptr = New OleDbDataAdapter(sql4, cnn)
adptr.Fill(ds4)
adptr.Dispose()
cnn.Close()
dt4 = ds4.Tables(0)
Form5.DataGridView1.DataSource = dt4
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Form5.DataGridView1.Visible = True
'For Account Executive
Dim dt5 As DataTable
Dim ds5 As New DataSet
cnn = New OleDbConnection(connectionString)
Dim accList As String = "("
For item5 As Integer = 0 To CheckedListBox6.CheckedItems.Count - 1
accList += "'" & CheckedListBox6.CheckedItems(item5) & "',"
Next
accList = accList.Substring(0, accList.Length - 1) + ")"
Dim sql5 = "select * from NTIdb where AccExec in " + accList
Try
cnn.Open()
adptr = New OleDbDataAdapter(sql5, cnn)
adptr.Fill(ds5)
adptr.Dispose()
cnn.Close()
dt5 = ds5.Tables(0)
Form5.DataGridView1.DataSource = dt5
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Form5.DataGridView1.Visible = True
推荐答案
这篇关于过滤按钮错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!