数据库无法显示出来,求帮调下错误
用的一般处理程序,想把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;
}
}
}