Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Datagridview筛选错误/Vb.net Sql_Sql_Vb.net_Datagridview_Listbox_Multipleselection - Fatal编程技术网

Datagridview筛选错误/Vb.net Sql

Datagridview筛选错误/Vb.net Sql,sql,vb.net,datagridview,listbox,multipleselection,Sql,Vb.net,Datagridview,Listbox,Multipleselection,我的问题是,我无法按listbox中的多个选定项筛选datagridview 我可以通过多个文本框、组合框和一个选定项列表框过滤datagridview。但是,我无法使用listbox多个选项进行筛选。有什么办法可以解决这个问题吗 任何帮助都将不胜感激。我将根据您的评论发布我的直觉: Text将为您提供第一个选定项。ToString()。这意味着,当您选择两个对象时,它仍然只显示第一个对象。您需要做的是循环遍历不同的ListBoxItems,并分别添加它们。所以你要找的是这样的东西: Dim R

我的问题是,我无法按listbox中的多个选定项筛选datagridview

我可以通过多个文本框、组合框和一个选定项列表框过滤datagridview。但是,我无法使用listbox多个选项进行筛选。有什么办法可以解决这个问题吗


任何帮助都将不胜感激。

我将根据您的评论发布我的直觉:

Text将为您提供第一个选定项。ToString()。这意味着,当您选择两个对象时,它仍然只显示第一个对象。您需要做的是循环遍历不同的ListBoxItems,并分别添加它们。所以你要找的是这样的东西:

Dim Result As String = String.Format("mycolumn2 Like '%{0}%' AND (", ComboBox1.Text)
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
    Result &= String.Format(" mycolumn Like '%{0}%'", ListBox1.SelectedItems(i).ToString)
    If i <> ListBox1.SelectedItems.Count - 1 Then
        Result &= " OR "
    Else
        Result &= ")"
    End If
Next
Dim Result As String=String.Format(“mycolumn2,如“{0}%”和(“,ComboBox1.Text”)
对于i As Integer=0的列表框1.SelectedItems.Count-1
Result&=String.Format(“类似于“{0}%”的mycolumn”,ListBox1.SelectedItems(i.ToString)
如果我列出box1.SelectedItems.Count-1,那么
结果&=“或”
其他的
结果(&=“”)
如果结束
下一个

我不确定这种偏执论是否会奏效,但我有一半的希望它会奏效。这将创建一个过滤器,要求mycolumn2与文本框匹配(如前所述),然后要求mycolumn与任何选定的ListBox1.Items匹配

sql标签?解释如何使用“@MYBindingSource.Filter=uu-String.Format”(“类似mycolumn的“%”和ListBox1.Text&“%”以及类似mycolumn2的“%”和ComboBox1.Text&“%”)这样的代码。我使用sql server-mdf。将代码放在问题中,而不是注释中。我有预感什么地方出了问题,但没有代码我不能确定。还要添加一些周围的代码,而不仅仅是那一行。