zoukankan      html  css  js  c++  java
  • 连接数据库智能感知

    前台代码:

    <head runat="server">
        <title></title>
        <link href="js/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
        <script src="js/Jquery1.7.js" type="text/javascript"></script>
        <script src="js/jquery.autocomplete.js" type="text/javascript"></script>
        <script src="js/jquery.autocomplete.pack.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/getGoods",
                    data: "{}",
                    success: function (result) {
                        var array = new Array();
                        for (var i = 0; i < result.d.length; i++) {
                            array.push(result.d[i]);
                        }
                        $('#txtQuery').autocomplete(array);
                    }
                })
            })

        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtQuery" runat="server"></asp:TextBox>
        </div>
        </form>
    </body>

    -------------------------WebServices-----------------------------

    namespace WebApplication1
    {
        /// <summary>
        /// WebService1 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
         [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {

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

            [WebMethod]
            public List<string> getGoods()
            {
                List<string> list = new List<string>();
                if (Context.Cache["goods"] == null)
                {
                    string conStr = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
                    SqlConnection conn = new SqlConnection(conStr);
                    conn.Open();
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "select T_GoodsTitle from T_Goods";
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        list.Add(reader["T_GoodsTitle"].ToString());
                    }
                    Context.Cache["goods"] = list;
                }
                else {
                    list = Context.Cache["goods"] as List<string>;
                }
                return list;
            }


        }
    }

  • 相关阅读:
    flume 使用遇到问题及解决
    定时任务 Linux cron job 初步使用
    java instrumentation &JVMTI
    Java远程执行Shell命令
    No input clusters found in output/ZS_TEST_OUTPUT3404268420/clusters-0/part-randomSeed. Check your -c argument.
    asp.net core 中读取post 方式来的内容
    C#程序 权限不够的解决方案
    wamp下安装https 实现 ssl 协议,主要是编写小程序通讯
    如何让thinkpad X1C 用U盘 安装上专业版win10
    php 5.4 5.5 如何连接 ms sqlserver
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3134733.html
Copyright © 2011-2022 走看看