パフォーマンスを向上させる必要があるかもしれない以下のコードについて、ご意見はありますか?これは.NET 2.0フレームワークであり、DataTableはDataGridviewにバインドされています。データは、データベースから来ていない.ReadXML()を介してDatatableにロードされます。 80から100kまでのレコードはどこにもあります。 Terms()配列は、ユーザーが検索に渡した配列です。したがって、 "bob taco"はterms(0)= "bob"、terms(1)= "taco"となります。私は引用された用語を維持する正規表現を持っています。したがって、 "bob taco"は配列の1つの要素になります。より良い方法がありますか?私はDataviewを使用してみましたが、これはパフォーマンスが向上していますが、LIKE演算子を使用できるようには見えませんでした。どんな提案も大歓迎です、私はこれを少しスピードアップしたいと思います。Datagridviewにデータテーブルをバインドする
Public Function Search(ByVal Terms() As String, ByRef ResidentTBL As DataTable) As DataTable
'Dim t As Long = Now.Ticks
Dim j As Integer
Dim newdt As New DataTable("Users")
Dim newtable As New DataTable
newtable = ResidentTBL.Clone
Dim termsceiling As Integer
termsceiling = Terms.GetUpperBound(0)
Dim filterstr As String = String.Empty
Dim foundrows() As DataRow
Dim sortOrder As String = "displayname ASC"
Dim tempstr As String
For j = 0 To termsceiling
'remedy any invalid sql characters
tempstr = Terms(j).Trim.ToUpper
tempstr = tempstr.Replace("'", "''")
tempstr = tempstr.Replace("*", "")
tempstr = tempstr.Replace("%", "")
'assemble the sql query
filterstr = filterstr & _
"((column1 LIKE '" & tempstr & "%') OR " & _
"(column2 LIKE '" & tempstr & "%') OR " & _
"(column3 LIKE '" & tempstr & "%') OR " & _
"(column4 LIKE '" & tempstr & "%') OR " & _
"(column5 LIKE '" & tempstr & "%') OR " & _
"(column6 LIKE '" & tempstr & "%') OR " & _
"(column7 LIKE '" & tempstr & "%') OR " & _
"(column8 LIKE '" & tempstr & "%') OR " & _
"(column9 LIKE '" & tempstr & "%') OR " & _
"(column10 LIKE '" & tempstr & "%'))"
'if there are further iterations append an AND (user typed more than one term)
If termsceiling > 0 And j <> termsceiling Then
filterstr = filterstr & " AND "
End If
Next j
filterstr = "(" & filterstr & ")" 'wrap the entire query
foundrows = ResidentTBL.Select(filterstr, sortOrder)
For i = 0 To foundrows.Length - 1
newtable.ImportRow(foundrows(i))
Next i
newdt = newtable
'Begin Debugging Code:
't = Now.Ticks - t
'MessageBox.Show("Took " & (t/10000000) & " seconds.")
'End Debugging Code:
Return newdt
End Function
BTW:Termが1次元配列の場合、termceiling変数内にLenghtプロパティを使用できます。 – smok1