作者maxpeter2100 (钓)
看板Ajax
标题[问题] 一个自动完成的问题
时间Mon May 18 22:15:42 2009
我写一个自动输入完成的功能
用Web Method
搭配ajaxtool的autocompleteextender
我web service 写法如下
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.Net;
using System.Data.OleDb;
using System.Collections.Generic;
namespace StockRiskManagement
{
/// <summary>
/// StockBuy 的摘要描述
/// </summary>
[WebService(Namespace = "
http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从指令码呼叫此 Web 服务,请取消注解下一行。
[System.Web.Script.Services.ScriptService]
public class StockBuy : System.Web.Services.WebService
{
public string[] GetNameGuggestion(string prefixText,int count)
{
//// 定义一个泛用集合物件 List 来储存建议词。
List<string> suggestions = new List<string>();
// 取得资料库连线字串设定,来建立 SQL 连线物件。
try
{
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=StockRiskManagement/mdb/Database.mdb";
OleDbConnection Con = new OleDbConnection(constr); //资料连结
物件 Con 的设定
Con.Open(); //连结资料库
// 指派查询陈述式。
string select = "SELECT DISTINCT 股票名称 FROM 公司资料 WHERE
股票名称 LIKE @prefixName "; //严重怀疑这行错了
OleDbCommand cmd = new OleDbCommand(select, Con); //设定命令物
件
// 设定参数值。
cmd.Parameters.AddWithValue("@prefixName", prefixText + "%");
OleDbDataReader dr = cmd.ExecuteReader();
int matchCount = 1;
while (dr.Read() && (matchCount <= count))
{
suggestions.Add(dr.GetString(0));
matchCount++;
}
return suggestions.ToArray();
}
catch (Exception ex)
{
suggestions.Add(ex.Message);
return suggestions.ToArray();
}
}
}
请问各位高手
这行应该怎麽写??
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.192.252.104
1F:推 bibo9901:这是java 不是javascript= = 05/18 22:27
2F:→ maxpeter2100:?? 我PO错地方了?? 05/18 22:28
3F:→ maxpeter2100:我以为是AJAX就可以丢进来..... 05/18 22:29
4F:→ maxpeter2100:补一下 这是C# 05/18 22:29
※ maxpeter2100:转录至看板 C_Sharp 05/18 22:30
5F:→ grence:中断点设一设,跑个侦错看suggestions.ToArray()有没有东西 05/18 22:45
6F:→ maxpeter2100:我放在updatepanel中 中断点怎麽设 都没感觉.... 05/18 22:53
7F:→ maxpeter2100:还是说有中断点还是有差??? 05/18 22:53
8F:→ TonyQ:一楼你搞错了 , 这是 c# 不是 java. XD 05/18 23:01
9F:→ grence:先看这个WebService回传什麽东西…中断点设在WebService里 05/19 01:36
10F:→ grence:要隔空抓药的话…AddWithValue改用Add指定参数资料类型试试 05/19 01:38
11F:→ maxpeter2100:我在C#也有问相同问题..... 哀 此题到底如何解 > < 05/19 22:03