簡體   English   中英

在 vb.net 中實現對大型數據庫有效的自動完成文本框?

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

在 Windows 應用程序中,我在使用大量項目(約 60000)填充自動完成字符串集合時遇到性能問題。 將數據從數據庫檢索到數據表足夠快(< 1 秒),但填充集合要慢得多,因為我正在遍歷數據表以填充集合。 有沒有更快的方法來執行這個操作。 我是這樣填充的:

    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

為什么要查詢如此大的集合以進行自動完成? 我會查詢諸如前 10 或 20 之類的內容

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

檢查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