如何在自动完成文本框中显示连接字符串 [英] how can I show concatenated string into autocomplete textbox

查看:90
本文介绍了如何在自动完成文本框中显示连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家



我想在自动填充文本框中显示连接字符串

当用户开始键入它时将按姓氏搜索。查询将查看数据库的全名包含...并在autosuggestion中显示全名,公司





如果我只是通过last_name搜索

并输入last_name MyCollection.Add(reader(last_name)。ToString())



它显示结果

但是下面的代码什么都没有显示



这里是我的代码



有人可以建议我如何解决这个问题吗?

Dear Experts

I am trying to show concatenated string into autocomplete textbox
when user start typing it will search by last name. query will look into database for full name contains ... and in autosuggestion it will show full name, company

.
if I just search by last_name
and put last_name MyCollection.Add(reader("last_name").ToString())

It shows result
however following code shows nothing

here is my code

can anyone please suggest me how to resolve this ?

Dim strauto As String

       Dim name As String
       name = Trim(txtCompanyKeyContacts.Text)
       If name = "" Then Exit Sub
       Dim cnString As String = ConfigurationManager.ConnectionStrings("dbcon").ConnectionString
       Dim con As New SqlConnection(cnString)

       Using con
           strauto = "SELECT (FULL_NAME + ',' + Company + ',' + Status) as contact  FROM name where FULL_NAME like '%" & Replace(name, "'", "''") & "%' "
           'SELECT last_name,FULL_NAME + ',' + Company + ',' + Status as contact FROM name"
           con.Open()
           Dim cmd As New SqlCommand(strauto, con)

           Dim reader As SqlDataReader = cmd.ExecuteReader()
           Dim MyCollection As New AutoCompleteStringCollection()

           If reader.HasRows = True Then
               While reader.Read()


                   ' MyCollection.Add(reader("FULL_NAME + ',' + Company + ',' + Status").ToString())
                   MyCollection.Add(reader("contact").ToString())
               End While
           End If

          

           txtCompanyKeyContacts.AutoCompleteCustomSource = MyCollection
           con.Close()
       End Using

推荐答案

大家好

无法找到解决方案,所以使用了combobox而不是文本框。

如果你必须知道问题,那么请发布解决方案。即使我选择了不同的路径,我也想知道这个问题的解决方案

感谢所有的时间..
Hi All
Couldnt find solution so used combobox instead of textbox.
if you got to know the problem then please post the solution. even if I've chosen a different path I'd like to know the solution for this problem
thanks all for your time..


这篇关于如何在自动完成文本框中显示连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆