.net 筛选数据库以不显示相同的数据

.net 筛选数据库以不显示相同的数据,.net,database,vb.net,ms-access,.net,Database,Vb.net,Ms Access,我将如何筛选此访问数据库: 使其在ComboBox1中看起来像这样 另外,我使用一个组合框来显示字段数据,我只使用数据绑定项来显示它的属性,因此最终它将显示它可以看到的所有数据,但我只希望该字段中的每个相同数据。我不是在编写代码,但任何一种方法都可以。谢谢 更新: 我想要的示例代码: Dim update() = FbuildingSettings.camButtonDtable.Select("Each of the Same data name") comboBox1.Items.Add(u

我将如何筛选此访问数据库: 使其在ComboBox1中看起来像这样 另外,我使用一个组合框来显示字段数据,我只使用数据绑定项来显示它的属性,因此最终它将显示它可以看到的所有数据,但我只希望该字段中的每个相同数据。我不是在编写代码,但任何一种方法都可以。谢谢 更新: 我想要的示例代码:

Dim update() = FbuildingSettings.camButtonDtable.Select("Each of the Same data name")
comboBox1.Items.Add(update)
' don't know if something like this will work.  
该代码引用自以下代码:该代码正在工作-该代码从ButtonText字段中的数据获取DVRIP的值

Dim host = FbuildingSettings.camButtonDtable.Select("ButtonText =" & "'" & sender.Text & "'")(0)("DVRIP")
' SELECT DVRIP WHERE ButtonText = CAMERA01 ~ I think its like this in SQL

可以使用数据源初始化源对象。这里有一个示例控制台应用程序,应该足够了

    Module Module1

        Sub Main()

            Dim source As New List(Of MyDataItems)()
            source.Add(New MyDataItems() With { _
      .DataValue = "CSI", _
      .DisplayText = "CSI" _
     })
            source.Add(New MyDataItems() With { _
      .DataValue = "CSI", _
      .DisplayText = "CSI" _
     })
            source.Add(New MyDataItems() With { _
      .DataValue = "Mall", _
      .DisplayText = "Mall" _
     })
            source.Add(New MyDataItems() With { _
      .DataValue = "Mall", _
      .DisplayText = "Mall" _
     })
            source.Add(New MyDataItems() With { _
      .DataValue = "House", _
      .DisplayText = "House" _
     })
            source.Add(New MyDataItems() With { _
      .DataValue = "House", _
      .DisplayText = "House" _
     })
            Console.WriteLine("Initial List items  contents")
            source.ForEach(Sub(m As MyDataItems) Console.WriteLine(m.DataValue))
            Console.WriteLine("List items after applying Filter")
            Dim distinctItems = source.GroupBy(Function(x) x.DisplayText).[Select](Function(y) y.First()).ToList
            distinctItems.ForEach(Sub(m As MyDataItems) Console.WriteLine(m.DataValue))
            Console.ReadLine()
        End Sub

    End Module
试试这个

SELECT Building
FROM TableName
GROUP BY Building;
试试这个

Dim dt As DataTable = camButtonDtable.DefaultView.ToTable(True, "Building")
comboBox1.DataValue = "Building"
comboBox1.DisplayText = "Building"
comboBox1.DataBind()

与其直接将数据源绑定到组合框,不如从数据源创建一个新的IList,并在将其绑定到组合框之前对该列表进行过滤。如果您认为这是一个更好的机会,请将其吐出来。正如我所说的,任何一种方法都可以,我只是想知道如何做到:如果你甚至要对字段中的所有数据进行编码,这将是一项艰巨的工作,而这些数据是用户创建的,你不必做,也无法做。当然是这样,但Leis似乎期待着一个详细的答案。实际上,答案只有一行:source.GroupByFunctionx x.DisplayText。[Select]Functiony.First.tolist在这一行出现异常:Dim update=FbuildingSettings.camButtonDtable.SelectBuilding FROM tblCamButtons GROUP BY Building~在“FROM”之后缺少操作数operator@AdorableVB你做错了。您没有包含SELECT子句,这使您的SQL语句出错。SQL语句应该是按建筑从TableName组中选择建筑。再次检查,.Selectstring这是SELECT子句。我不能像右选择那样使用它?嗯,实际上我不熟悉你正在使用的对象。您正在winforms、wpf上使用VB.NET?或者那个宏是用于访问的?我不完全确定如何使用该对象及其属性和方法。你能解释一下你从哪里得到的吗?我使用VB.net,检查更新的问题,希望你能了解我是如何利用SELECT子句编写VB代码的