<%@ WebService Language="C#" Class="Customers" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

using System.Data;
using System.Data.OleDb;
using System.Configuration;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Customers  : System.Web.Services.WebService {
  
    [WebMethod]
    public string[] GetNames(string PrefixText, int count) {
      string selectString = "SELECT TOP 10 CompanyName FROM Customers WHERE CompanyKana Like ?";
      OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["NwindConnectionString"].ConnectionString);
      OleDbDataAdapter da = new OleDbDataAdapter();
      OleDbCommand cmd = new OleDbCommand(selectString, con);
      DataTable dt = new DataTable();
      cmd.Parameters.AddWithValue("?", PrefixText + "%");
      da.SelectCommand = cmd;
      da.Fill(dt);
      int size = Math.Min(dt.Rows.Count, count) - 1;
      string[] output = new string[size + 1];            
      int i = 0;
      foreach (DataRow dr in dt.Rows) {
        if (i > size) {
          break;
        }
        output[i] = (string)dr[0];
        i += 1;
      }
      return output;
    }
       
}