【问题标题】:Get rid of duplicate items in ComboBox from a BLOB database从 BLOB 数据库中删除 ComboBox 中的重复项
【发布时间】:2016-10-13 01:31:56
【问题描述】:

我在显示我的数据库中保存的 BLOB 的组合框中得到重复项。

Private Sub refreshBLOBList()
    Dim getBLOBListCommand As New SqlCommand( _
        "SELECT DISTINCT FileName FROM DocumentStorage", dbConnection)
    Dim reader As SqlDataReader

    getBLOBListCommand.Connection.Open()
    reader = getBLOBListCommand.ExecuteReader
    While reader.Read
        BLOBList.Items.Add(reader(0))
    End While

    reader.Close()
    getBLOBListCommand.Connection.Close()

    BLOBList.SelectedIndex = 0
End Sub

在这个块中,我刷新了组合框,但 DISTINCT 并没有摆脱组合框中的欺骗。奇怪的是,当我查询它并将其放入 datagridview 时,我得到了我想要的数据集。

有什么建议吗?

【问题讨论】:

  • 我认为您需要在添加项目之前致电BLOBList.Clear()。否则,您只需再次添加所有不同的新项
  • @FloatingKiwi 你是对的,这解决了我的问题。谢谢!

标签: sql vb.net visual-studio combobox blob


【解决方案1】:

我需要在添加项目之前调用 BLOBlist.items.clear() 否则我将再次添加不同的项目。

【讨论】:

    【解决方案2】:

    您不需要“DISTINCT”。只需 BLOBList.items.clear()

    【讨论】:

    • 欢迎来到 Stack Overflow。你能edit你的答案提供更多细节吗?
    猜你喜欢
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2014-08-22
    • 2012-11-28
    • 1970-01-01
    相关资源
    最近更新 更多