用的一般处理程序,想把chen表中内容显示出来,但是显示只有Hello World而已,没有报错,而且如果把Hello World的那2行给注释,就会报   XML解析错误:未找到元素  这个错误<%@ WebHandler Language="C#" Class="Handler" %>using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
       context.Response.Write("Hello World");
        DataTable dt = LoadData();
        StringBuilder sb = new StringBuilder();
        sb.Append("\t<table id=\"tStus\">");
        foreach (DataRow dr in dt.Rows)
        {
            sb.AppendLine("\t<tr>");
            sb.AppendLine("\t\t<td>" + dr["S_number"].ToString() + "</td>");
            sb.AppendLine("\t</tr>");
        }
        sb.Append("\t</table>");
    }
    
    
    public DataTable LoadData()
    {
        DataTable dt = null;
        try
        {
            SqlConnection conn = new SqlConnection(@"server=.;database=Sales;Integrated Security=True;");
             string strSql = "select * from chen";
            SqlDataAdapter da = new SqlDataAdapter(strSql,conn);
            dt = new DataTable();
            da.Fill(dt);
        }
        catch (Exception ex)
        {        }
        return dt;
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }}

解决方案 »

  1.   

    我又看出来 
    sb.AppendLine 之后  sb 跟context.Response  没有过交流
      

  2.   

     public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
           context.Response.Write("Hello World");
            DataTable dt = LoadData();
            StringBuilder sb = new StringBuilder();
            sb.Append("\t<table id=\"tStus\">");
            foreach (DataRow dr in dt.Rows)
            {
                sb.AppendLine("\t<tr>");
                sb.AppendLine("\t\t<td>" + dr["S_number"].ToString() + "</td>");
                sb.AppendLine("\t</tr>");
            }
            sb.Append("\t</table>");
        }
        Response.Write(sb.ToString());
      

  3.   

    这种输出很难控制样式。。而且不好调试。。建议写好thml模板。。用<%= num%>这种方式