62,267
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetData(string prefixText,int count)//这里的参数必须固定
{
SqlConnection conn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=;");
string Str = "select CompanyName from Customers where CompanyName like '" + prefixText + "%' order by CompanyName ";
SqlDataAdapter sda = new SqlDataAdapter(Str,conn);
DataSet ds=new DataSet();
sda.Fill(ds,"com");
string[] temp=new string[ds.Tables["com"].Rows.Count];
for(int i=0;i<ds.Tables["com"].Rows.Count;i++)
{
temp[i] = ds.Tables["com"].Rows[i]["CompanyName"].ToString();
}
return temp;
}
}
<asp:ScriptManager ID="scriptmanager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<cc1:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="TextBox1"
ServiceMethod="GetCompletionList"
ServicePath="ToolkitTestService.asmx"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionSetCount="5"
CompletionInterval="100"
/>