[問題] 一個自動完成的問題
我寫一個自動輸入完成的功能
用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
推
05/18 22:27, , 1F
05/18 22:27, 1F
→
05/18 22:28, , 2F
05/18 22:28, 2F
→
05/18 22:29, , 3F
05/18 22:29, 3F
→
05/18 22:29, , 4F
05/18 22:29, 4F
※ maxpeter2100:轉錄至看板 C_Sharp 05/18 22:30
→
05/18 22:45, , 5F
05/18 22:45, 5F
→
05/18 22:53, , 6F
05/18 22:53, 6F
→
05/18 22:53, , 7F
05/18 22:53, 7F
→
05/18 23:01, , 8F
05/18 23:01, 8F
→
05/19 01:36, , 9F
05/19 01:36, 9F
→
05/19 01:38, , 10F
05/19 01:38, 10F
→
05/19 22:03, , 11F
05/19 22:03, 11F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章