Imports System.Data.SqlClient
Imports System.Collections.Generic

Partial Class VB
    Inherits System.Web.UI.Page

    <System.Web.Script.Services.ScriptMethod(), _
    System.Web.Services.WebMethod()> _
   Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
        Dim conn As SqlConnection = New SqlConnection
        conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Dim cmd As SqlCommand = New SqlCommand
        cmd.CommandText = "select CustomerId, ContactName from Customers where" & _
        " ContactName like @SearchText + '%'"
        cmd.Parameters.AddWithValue("@SearchText", prefixText)
        cmd.Connection = conn
        conn.Open()
        Dim customers As List(Of String) = New List(Of String)
        Dim sdr As SqlDataReader = cmd.ExecuteReader
        While sdr.Read
            Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr("ContactName").ToString, sdr("CustomerId").ToString)
            customers.Add(item)
        End While
        conn.Close()
        Return customers
    End Function

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim customerId As String = Request.Form(hfCustomerId.UniqueID)
        Dim customerName As String = Request.Form(txtCustomer.UniqueID)
    End Sub
End Class
