这期内容当中小编将会给大家带来有关如何在asp.net中异步获取datatable,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联公司是一家专业提供兴和企业网站建设,专注与成都网站制作、做网站、H5开发、小程序制作等业务。10年已为兴和众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。前台代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MethodOne.aspx.cs" Inherits="_Default" %>
处理页面程序如下:
<%@ 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"; if (context.Request.QueryString["flag"].Equals("data")) { context.Response.Write(GetResult(5,Int32.Parse(context.Request.QueryString["index"]))); } if (context.Request.QueryString["flag"].Equals("count")) { context.Response.Write(getCount()); } } private string GetResult() { DataTable dt = new DataTable(); using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"])) { conn.Open(); string sql = "SELECT * FROM TestBlog "; SqlDataAdapter sda = new SqlDataAdapter(sql, conn); sda.Fill(dt); } int rLen = dt.Rows.Count; int cLen = dt.Columns.Count; StringBuilder sb = new StringBuilder(); for (int j = 0; j < rLen; j++) { sb.Append(""); for (int i = 0; i < cLen; i++) { sb.Append(" "); } return sb.ToString(); } private string GetResult(int pagecount,int currentpage) { DataTable dt = new DataTable(); using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"])) { conn.Open(); string sql = "SELECT TOP "+pagecount+" * FROM TestBlog tb WHERE ydid NOT IN (SELECT TOP "+pagecount*(currentpage-1)+" ydid FROM TestBlog tb2) "; SqlDataAdapter sda = new SqlDataAdapter(sql,conn); sda.Fill(dt); } int rLen = dt.Rows.Count; int cLen = dt.Columns.Count; StringBuilder sb = new StringBuilder(); for (int j = 0; j < rLen; j++) { sb.Append(""); sb.Append(dt.Rows[j][i].ToString()); sb.Append(" "); } sb.Append(""); for (int i = 0; i < cLen; i++) { sb.Append(" "); } return sb.ToString(); } private string getCount() { DataTable dt = new DataTable(); using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"])) { conn.Open(); string sql = "select count(*) from testblog"; SqlDataAdapter sda = new SqlDataAdapter(sql, conn); sda.Fill(dt); } return dt.Rows[0][0].ToString(); } public bool IsReusable { get { return false; } } }"); sb.Append(dt.Rows[j][i].ToString()); sb.Append(" "); } sb.Append("
上述就是小编为大家分享的如何在asp.net中异步获取datatable了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款