<%@ WebService Language="VB" Class="Customers" %>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

Imports System.Data
Imports System.Data.OleDb
  
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class Customers
  Inherits System.Web.Services.WebService
    
  <WebMethod()> _
  Public Function GetNames(ByVal PrefixText As String, ByVal count As Integer) As String()
    Dim selectString As String = "SELECT TOP 10 CompanyName FROM Customers WHERE CompanyKana Like ?"
    Dim con As New OleDbConnection(connectionString)
    Dim da As New OleDbDataAdapter
    Dim cmd As New OleDbCommand(selectString, con)
    Dim dt As New DataTable
    cmd.Parameters.AddWithValue("?", PrefixText & "%")
    da.SelectCommand = cmd
    da.Fill(dt)
    Dim size As Integer = Math.Min(dt.Rows.Count, count) - 1
    Dim output(size) As String
    Dim i As Integer = 0
    For Each dr As DataRow In dt.Rows
      If i > size Then
        Exit For
      End If
      output(i) = dr(0)
      i += 1
    Next
    Return output
  End Function

  Public Shared ReadOnly Property connectionString() As String
    Get
      connectionString = ConfigurationManager.ConnectionStrings("NwindConnectionString").ConnectionString
    End Get
  End Property

End Class
