Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 自动建议文本框_Sql Server_Vb.net_Sql Server 2005 - Fatal编程技术网

Sql server 自动建议文本框

Sql server 自动建议文本框,sql-server,vb.net,sql-server-2005,Sql Server,Vb.net,Sql Server 2005,我想有一个自动建议文本框,它会显示员工的名字后,键入一个具体的信。名称在employee表中分为三列,即firstname、middlename和lastname 我尝试了一个代码,但它只能显示表的一列,即firstname。 如何连接所有三列,以便在文本框中建议它们 我的代码: Dim strSql As String = "select P_Firstname, P_MiddleName, P_LastName from Patient_Registration" Dim d

我想有一个自动建议文本框,它会显示员工的名字后,键入一个具体的信。名称在employee表中分为三列,即firstname、middlename和lastname

我尝试了一个代码,但它只能显示表的一列,即firstname。 如何连接所有三列,以便在文本框中建议它们

我的代码:

Dim strSql As String = "select P_Firstname, P_MiddleName, P_LastName from Patient_Registration"
        Dim dtb As New DataTable
        Using cnn As New SqlConnection(conn)
            cnn.Open()
            Using dad As New SqlDataAdapter(strSql, cnn)
                dad.Fill(dtb)
            End Using
            cnn.Close()
        End Using
        txtsearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        txtsearch.AutoCompleteSource = AutoCompleteSource.CustomSource
        If dtb.Rows.Count > 0 Then
            Dim i As Integer = 0
            For i = 0 To (dtb.Rows.Count - 1)
                txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName"))
            Next
        End If
使用:

而不是:

For i = 0 To (dtb.Rows.Count - 1)
    txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName"))
Next
[在此处输入图像描述][1]
[1]: https://i.stack.imgur.com/g6TR9.png
显示上述结果。
在这里输入代码
我的代码是:
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
公共静态列表GetCenter(字符串前缀、int计数)
{
使用(SqlConnection conn=newsqlconnection())
{
conn.ConnectionString=ConfigurationManager.AppSettings[“ConnectionString”].ToString();
使用(SqlCommand cmd=new SqlCommand())
{
string cmdText=“从活动=1的中心\u主机选择中心名,中心名类似“%”++@SearchText++“%”;
cmd.Parameters.AddWithValue(“@SearchText”,prefixText);
cmdText+=“按中心名排序”;
cmd.CommandText=cmdText;
cmd.Connection=conn;
conn.Open();
列出客户=新列表();
使用(SqlDataReader sdr=cmd.ExecuteReader())
{
while(sdr.Read())
{
添加(sdr[“centername”].ToString());
}
}
康涅狄格州关闭();
返回客户;
}
}
}

For i = 0 To (dtb.Rows.Count - 1)
    txtsearch.AutoCompleteCustomSource.Add(dtb.Rows(i)("P_FirstName"))
Next
[enter image description here][1]


  [1]: https://i.stack.imgur.com/g6TR9.png

Showing above result.



    enter code here

My code is :

 [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetCenter(string prefixText, int count)
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
            using (SqlCommand cmd = new SqlCommand())
            {
                string cmdText = "Select centername from Center_Master WHere Active=1 and centername like '%' +@SearchText  + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);

                cmdText += " order by centername ";
                cmd.CommandText = cmdText;
                cmd.Connection = conn;
                conn.Open();
                List<string> customers = new List<string>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        customers.Add(sdr["centername"].ToString());
                    }
                }
                conn.Close();
                return customers;
            }
        }
    }
 <asp:TextBox ID="ddlcenter" runat="server" Font-Size="10px" TabIndex="1" Width="150px"
                                                                    Style="text-transform: capitalize;"
                                                                    placeholder="Type Center Name/Code" autocomplete="off"></asp:TextBox>
                                                                <cc1:AutoCompleteExtender ServiceMethod="GetCenter" MinimumPrefixLength="2" CompletionInterval="100"
                                                                    EnableCaching="false" CompletionSetCount="10" TargetControlID="ddlcenter" UseContextKey="true"
                                                                    ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false" CompletionListCssClass="completionList"
                                                                    CompletionListHighlightedItemCssClass="itemHighlighted" CompletionListItemCssClass="listItem">
                                                                </cc1:AutoCompleteExtender>