把DataTble中的字段拼接进字符串的写法

来源:互联网 发布:淘宝啥时候能买彩票 编辑:程序博客网 时间:2024/06/07 09:14

 

 

<%@ WebHandler Language="C#" Class="GetcityByProvinceIDHandler" %>
 

using System;
using System.Web;
public class GetcityByProvinceIDHandler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        int ID=Convert.ToInt32( context.Request["ID"]);//取到传过来的ID值
        BLL.StaticDataBll bll = new BLL.StaticDataBll();
        System.Data.DataTable table = bll.getCityByProvinceID(ID);//得到市的数据源
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        foreach (System.Data.DataRow row in table.Rows)
        {
            sb.Append(row["ID"].ToString()).Append("|").Append(row["FName"].ToString()).Append("$");
            //context.Response.Write(row[]);
            //sb.Append(row["ID"].ToString()).Append("|");
        }
        context.Response.Write(sb.ToString().Trim('$'));       
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}

 

原创粉丝点击