DAL层
using System;
using System.Collections.Generic;
using System.Text;
using MODEL;
using System.Da
using System.Da
namespace DAL
{
public static class ArticleService
{
/*************************************************************************************/
//datatable方法
public static DataTable GetDataTable()
{
string strsql = "select * from t_Article";
try
{
DataTable dt = DBHelper.GetDataTable(strsql);
return dt;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//public static void a()
//{
// SqlConnection conn = new SqlConnection("server=AA296D9D5D2B411;database=accp;uid=sa;pwd=accp;");
// string strsql = "select * from test where name=" + name;
// SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
// DataTable dt = new DataTable();
// conn.Open();
// sda.Fill(dt);
// Label1.Text = dt.Rows[0]["age"].ToString();
//}
}
}
BLL层
using System;
using System.Collections.Generic;
using System.Text;
using MODEL;
using DAL;
using System.Da
namespace BLL
{
public class ArticleManager
{
//用DataTable查询
public static DataTable GetDataTable()
{
return ArticleService.GetDataTable();
}
}
}
MODEL层
using System;
using System.Collections.Generic;
using System.Text;
namespace MODEL
{
public class Article
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string title;
public string Title
{
get { return title; }
set { title = value; }
}
private string content;
public string Content
{
get { return content; }
set { content = value; }
}
private DateTime time;
public DateTime Time
{
get { return time; }
set { time = value; }
}
private string url;
public string Url
{
get { return url; }
set { url = value; }
}
}
}
WEB层
show.aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="show" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" On
</asp:GridView>
<div>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</body>
</html>
show.aspx.cs代码
using System;
using System.Da
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using MODEL;
using System.Collections.Generic;
using System.Da
public partial class show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
/*************************************************************************************/
//用DataTable获得数据集(普通的显示)
//DataTable dt = ArticleManager.GetDataTable();
//Label1.Text = dt.Rows[0]["t_ID"].ToString();
//Label2.Text = dt.Rows[0]["t_Title"].ToString();
//Label3.Text = dt.Rows[0]["t_Content"].ToString();
//用DataTable获得数据集(普通的显示)
//DataTable d = ArticleManager.GetDataTable();
//foreach (DataRow row in d.Rows)
//{
// string id = row["t_ID"].ToString();
// string title = row["t_Title"].ToString();
// string content = row["t_Content"].ToString();
// string datae = row["t_Date"].ToString();
// Label lbl1 = new Label();
// Label lbl2 = new Label();
// lbl1.Text = id;
// lbl2.Text = title;
// Label1.Text += lbl1.Text + "<br>";
// Label2.Text += lbl2.Text + "<br>";
//}
//GridView控件用DateTable绑定
//DisplayDateTable();
/*************************************************************************************/
}
}
}
//DataTable绑定
public void DisplayDateTable()
{
DataTable dt = ArticleManager.GetDataTable();
GridView1.DataSource = dt;
GridView1.DataBind();
}
//分页时调用
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//DataSet绑定
GridView1.PageIndex = e.NewPageIndex;
DisplayDateTable();
}
}