在wpf中获取AutoCompleteBox中的错误 [英] Getting error in AutoCompleteBox in wpf
本文介绍了在wpf中获取AutoCompleteBox中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我写了下面的代码来填写autocompletebox但我收到错误..
代码:
Hi all
I wrote the below code to fill a autocompletebox but i am getting error..
Code:
Dim command As New SqlCommand("Select CompanyName from Transportation_Courier_AddressDiary where PaymentTerms IS NULL", connection)
Dim da1 As New SqlDataAdapter(command)
da1.Fill(dtt)
For Each dr1 As DataRow In dtt.Rows
list.Add(dr1("CompanyName").ToString())
Next
txtcname.ItemsSource = Nothing
txtcname.ItemsSource = list
txtcname.PopulateComplete()
错误:
系统.windows.controls.input.toolkit.dll!system.windows.controls.AutoCompleteBox.PopulateComplete()第2178行
我用google搜索但没有得到任何答案..
请告诉我这个问题。
Error:
system.windows.controls.input.toolkit.dll!system.windows.controls.AutoCompleteBox.PopulateComplete() Line 2178
I googled also but not getting any answer for it..
Please tell me the problem.
推荐答案
试试这个。只需将MySQL类更改为SQL
Try this. Just change the MySQL class to SQL
'DECLARE
Private namesCollection1 As New AutoCompleteStringCollection()
' ON FORM LOAD EVENT
FillData()
txtcname.AutoCompleteMode = AutoCompleteMode.Suggest
txtcname.AutoCompleteSource = AutoCompleteSource.CustomSource
txtcname.AutoCompleteCustomSource = namesCollection1
Private Sub FillData()
Dim cn As New MySqlConnection
Dim cmd As New MySqlCommand
cn = New MySqlConnection
cn.ConnectionString = "server=localhost; user id=root; password=3; database=db"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM student_info where firstname like '%" & TextBox4.Text & "%'"
Dim dr As MySqlDataReader = cmd.ExecuteReader()
If dr.HasRows = True Then
While dr.Read()
namesCollection1.Add(dr("firstname").ToString())
End While
End If
dr.Close()
End Sub
这篇关于在wpf中获取AutoCompleteBox中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文