当前位置:编程学习 > C#/ASP.NET >>

数据库无法显示出来,求帮调下错误

用的一般处理程序,想把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;
        }
    }

} --------------------编程问答-------------------- 我又看出来 
sb.AppendLine 之后  sb 跟context.Response  没有过交流 --------------------编程问答--------------------  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()); --------------------编程问答-------------------- 楼上说得没错 --------------------编程问答-------------------- 帮顶! --------------------编程问答-------------------- 除 --------------------编程问答--------------------
引用 2 楼 nice_fish 的回复:
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
       context.Response.Write("Hello World");
        DataTable dt = LoadData()……


确实  --------------------编程问答--------------------
引用 2 楼 nice_fish 的回复:
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
       context.Response.Write("Hello World");
        DataTable dt = LoadData()……
+1 --------------------编程问答-------------------- 就好像拍好了录像而没有放映一样。 --------------------编程问答--------------------
引用 2 楼 nice_fish 的回复:
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
       context.Response.Write("Hello World");
        DataTable dt = LoadData();
        St……
谢谢啊,我回去试试看看 --------------------编程问答--------------------
引用 8 楼 tianruo5260 的回复:
就好像拍好了录像而没有放映一样。
谢谢大家啊,非常感谢 --------------------编程问答--------------------
引用 1 楼 xiaobingking 的回复:
我又看出来 
sb.AppendLine 之后  sb 跟context.Response  没有过交流
谢谢大家啊,非常感谢 --------------------编程问答--------------------
引用 2 楼 nice_fish 的回复:
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
       context.Response.Write("Hello World");
        DataTable dt = LoadData();
        St……
这种输出很难控制样式。。而且不好调试。。建议写好thml模板。。用<%= num%>这种方式
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,