当前位置: 动力学知识库 > 问答 > 编程问答 >

selecting two column for autocomplete in vb.net

问题描述:

i created a code for autocomplete in textbox

my code is

 Try

Dim adapter As New OleDb.OleDbDataAdapter

con = New System.Data.OleDb.OleDbConnection(connectionString)

con.Open()

Dim dt As New DataTable

Dim ds As New DataSet

sqlstr = "select customerid,cname from customer "

ds.Tables.Add(dt)

adapter.SelectCommand = New OleDb.OleDbCommand(sqlstr, con)

adapter.Fill(dt)

Dim r As DataRow

txtcname.AutoCompleteCustomSource.Clear()

For Each r In dt.Rows

txtcname.AutoCompleteCustomSource.Add(r.Item(1).ToString)

Next

con.Close()

Catch ex As Exception

MsgBox("error found")

End Try

now i want through autocomplete i can select the selected column of id so that i can use that id in my next code to fetch the information of the customer

currently i am using this

Dim adapter As New OleDb.OleDbDataAdapter

con = New System.Data.OleDb.OleDbConnection(connectionString)

con.Open()

Dim dt As New DataTable

Dim ds As New DataSet

sqlstr = "select address1,mobileno from customer where cname='" & txtcname.Text & "' "

ds.Tables.Add(dt)

adapter.SelectCommand = New OleDb.OleDbCommand(sqlstr, con)

adapter.Fill(dt)

lbladdr.Text = dt.Rows(0).Item(0)

lblmono.Text = dt.Rows(0).Item(1).ToString

con.Close()

working fine but i have a primary key id in the customer table so how can i search information through the id of a customer ,

分享给朋友:
您可能感兴趣的文章:
随机阅读: