简体   繁体   English

在 vb.net 中实现对大型数据库有效的自动完成文本框?

[英]Implement an autocomplete textbox that is efficient with large database in vb.net?

In a Windows application, I'm experiencing performance issues when populating autocompletestring Collection with a large number of items (appr. 60000).在 Windows 应用程序中,我在使用大量项目(约 60000)填充自动完成字符串集合时遇到性能问题。 Retrieving the data from the database to a datatable is quick enough(< 1 sec), but populating the Collection is much slower since I am iterating through a datatable to fill the collection.将数据从数据库检索到数据表足够快(< 1 秒),但填充集合要慢得多,因为我正在遍历数据表以填充集合。 Is there a quicker way to perform this operation.有没有更快的方法来执行这个操作。 I'm populating like this:我是这样填充的:

    Private Sub txtName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtName.KeyDown
    If txtName.TextLength = 2 And e.KeyCode <> Keys.Back Then
        DataCollection.Clear()
        pObjDT = pobjDB.GetDT("Select Name from partymaster where AgentRef ='" & txtAgent.Text & "' And  Name LIKE '" & txtName.Text & "%' ")
        If Not pObjDT Is Nothing Then
            For Each lObjDataRow As DataRow In pObjDT.Rows
                DataCollection.Add(lObjDataRow.Item(0))
            Next
        End If
    End If
End Sub

Why you query so big collection for autocomplete?为什么要查询如此大的集合以进行自动完成? I would query something like top 10 or 20 like我会查询诸如前 10 或 20 之类的内容

Select top 10 Name from partymaster where AgentRef ='" & txtAgent.Text & "' And  Name LIKE '" & txtName.Text & "%

Check if AddRange() is more efficient than for each:检查AddRange()是否比每个都更有效:

Dim theStrings As String() = pObjDT.AsEnumerable().Select(Function(therow)
                                                             Return therow(0).ToString()
                                                          End Function).ToArray()
 DataCollection.AddRange(theStrings)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM