首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Linq从数据库获取数据到Gaia自动完成程序?

如何使用Linq从数据库获取数据到Gaia自动完成程序?
EN

Stack Overflow用户
提问于 2011-11-21 15:34:20
回答 1查看 675关注 0票数 0

我是linq的新手。我正在使用Gaia ajax Auto completer。我想要显示来自数据库表的搜索项。我想使用linq/ Active Records来完成此操作。我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2011-11-21 15:54:41

您需要使用web服务来使用自动完成程序填充文本字段。试试看..

代码语言:javascript
复制
    using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Script.Services;



namespace YourProject
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    // [ScriptService]
    //[System.Web.Script.Services.ScriptService()]
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 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 WebService : System.Web.Services.WebService
    {

        protected void Page_Load(object sender, EventArgs e)    
        {

        }
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]
        public string[] GetCompletionList(string prefixText)
        {

            string sql = "Select productname from F_Product Where productname like @prefixText ";
            SqlDataAdapter da = new SqlDataAdapter(sql, System.Configuration.ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString);
            da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
            DataTable dt = new DataTable();
            da.Fill(dt);
            string[] items = new string[dt.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                items.SetValue(dr["productname"].ToString(), i);
                i++;
            }
            return items;
        }
 }
}

如果你觉得有用,请标记为你的答案,否则让我知道…我一定会帮你的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8208572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档