using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Configuration;
///<summary>
/// Summary description for AutoComplete
///</summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
// uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
public AutoComplete()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 0;
string sql = "Select CountryName from country Where CountryName like @prefixText";
MySqlDataAdapter da = new MySqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["mydbConnectionString"].ConnectionString);
// da.SelectCommand.Parameters.Add("@prefixText", MySqlDbType.VarChar, 50).Value = prefixText+"%";
da.SelectCommand.Parameters.AddWithValue("@prefixText", string.Format("%{0}%", prefixText));
DataTable dt = new DataTable();
da.Fill(dt);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Columns.Count; i++)
{
items.Add(dt.Rows[i]["CountryName"].ToString());
}
return items.ToArray();
}
}