用的一般处理程序,想把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;
}
}}
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;
}
}}
解决方案 »
- 数据库设计问题思考
- 球衣方法删选重复数据
- 在oa中使用word客户端在线编辑
- 有关ASP.NEt的Timer 的问题 在线等 ,谢谢
- Is it meaning that I have to install SQL server in this Windows Server?
- 关于安装.net framework 2.0的问题 谢谢大家啊
- 用drawing类生成图片加水印后,如何保存该图片
- 如何把各页面从数据库中读取的相同的数据用一个类似全局变量的东西在系统初始化阶段保存起来?
- DataGrid有一列bit类型数据,默认显示为true/false,如何使其显示为true是为"正常",false为"失效"
- 请问如何在一个网页发回客户端之前,获得网页的代码
- 用ie登录校园网的时候怎么会跳转其他页面关于有图片帮忙看看啊!
- 打开一个已存在的excel文件
sb.AppendLine 之后 sb 跟context.Response 没有过交流
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());