关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

数据库返回json的方法

发布时间:2019-11-18 09:56:17

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Data;

using System.Data.Sql;

using System.Data.SqlClient;

using DTcms.Common;

using NetWing.Common.Data.SQLServer;

namespace DTcms.Web.api.region

{

    /// <summary>

    /// region_search 的摘要说明

    /// </summary>

    public class region_search : IHttpHandler

    {

        public void ProcessRequest(HttpContext context)

        {

            context.Response.ContentType = "text/plain";

            //context.Response.Write("Hello World");

            if (context.Request["type"]=="searcharea")

            {

                if (!string.IsNullOrEmpty(context.Request["keyword"]))

                {

                    DataTable dt = SqlEasy.ExecuteDataTable("select * from nw_region where MergerName like '%"+context.Request["keyword"]+"%' or [name] like '%"+context.Request["keyword"]+ "%' or Pinyin like '%"+context.Request["keyword"]+"%'");

                    string json=JsonHelper.DataTableToJSON(dt);

                    context.Response.Write(json);

                }

                else

                {

                }

            }

        }

        public bool IsReusable

        {

            get

            {

                return false;

            }

        }

    }

}




/template/Home/Zkeys/PC/Static