asp.net三层结构 datalist aspnetpager用法具体的
第一步引用到工具箱我知道第二步:干嘛第三步 我的是三层的所有就比较麻烦,请详细讲解一下数据访问层的怎么执行存储过程跟返回数据源然后在web页面绑定数据集的时候要...
第一步引用到工具箱我知道第二步:干嘛第三步 我的是三层的所有就比较麻烦,请详细讲解一下数据访问层的怎么执行存储过程跟返回数据源然后在web页面绑定数据集的时候要怎么写一些 aspnetpager中的一些属性要怎样 存储过程是那控件自动生成的那个还是要另外写一个 主要是数据层的数据获取方法跟web层的绑定 不要复制来答 俺搜了很久没一个具体点的
展开
3个回答
展开全部
sqlhelper里面
//分页
public static SqlDataReader PageReader(string sqlcmd, params SqlParameter[] pars)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = cons;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlcmd;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(pars);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return sdr;
}
BLL里面
//分页
public static List<ModelNew> admin_GetAll_S(int startIndex, int pageSize)
{
int endIndex = startIndex + pageSize - 1;
string sqlcmd = "NewPage_S";
SqlParameter pa1 = new SqlParameter("@startIndex", startIndex);
SqlParameter pa2 = new SqlParameter("@endIndex", endIndex);
List<ModelNew> list = new List<ModelNew>();
SqlDataReader sdr = SqlHelper.PageReader(sqlcmd, pa1, pa2);
while (sdr.Read())
{
ModelNew mn = new ModelNew();
mn.NewID = sdr.GetInt32(0);
mn.NewTitle = sdr.GetString(1);
mn.NewSource = sdr.GetString(2);
mn.NewKeywords = sdr.GetString(3);
mn.NewDescription = sdr.GetString(4);
mn.NewAbstract = sdr.GetString(5);
mn.NewText = sdr.GetString(6);
mn.NewTime = sdr.GetDateTime(7);
list.Add(mn);
}
return list;
}
//数量
public static string admin_GetCount_S()
{
string sqlcmd = "select count(*) from New";
object obj = SqlHelper.ExeOnlyOne(sqlcmd);
return obj.ToString() == "0" ? "0" : obj.ToString();
}
cs page_load里面
//分页控件赋值
AspNetPager1.RecordCount = int.Parse(BLLNew.admin_GetCount_S());
sql存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE [dbo].[NewPage_S]
(@startIndex INT,
@endIndex INT
)
AS
begin
WITH NewPageTab AS (
SELECT ROW_NUMBER() OVER (ORDER BY [NewID] desc)AS Row,[NewID],NewTitle,NewSource,NewKeywords,NewDescription,NewAbstract,NewText,NewTime
from New)
SELECT [NewID],NewTitle,NewSource,NewKeywords,NewDescription,NewAbstract,NewText,NewTime
FROM NewPageTab
WHERE Row between @startIndex and @endIndex
end
都按照位置写好 然后绑定aspnetpager就行了...
//分页
public static SqlDataReader PageReader(string sqlcmd, params SqlParameter[] pars)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = cons;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlcmd;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(pars);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return sdr;
}
BLL里面
//分页
public static List<ModelNew> admin_GetAll_S(int startIndex, int pageSize)
{
int endIndex = startIndex + pageSize - 1;
string sqlcmd = "NewPage_S";
SqlParameter pa1 = new SqlParameter("@startIndex", startIndex);
SqlParameter pa2 = new SqlParameter("@endIndex", endIndex);
List<ModelNew> list = new List<ModelNew>();
SqlDataReader sdr = SqlHelper.PageReader(sqlcmd, pa1, pa2);
while (sdr.Read())
{
ModelNew mn = new ModelNew();
mn.NewID = sdr.GetInt32(0);
mn.NewTitle = sdr.GetString(1);
mn.NewSource = sdr.GetString(2);
mn.NewKeywords = sdr.GetString(3);
mn.NewDescription = sdr.GetString(4);
mn.NewAbstract = sdr.GetString(5);
mn.NewText = sdr.GetString(6);
mn.NewTime = sdr.GetDateTime(7);
list.Add(mn);
}
return list;
}
//数量
public static string admin_GetCount_S()
{
string sqlcmd = "select count(*) from New";
object obj = SqlHelper.ExeOnlyOne(sqlcmd);
return obj.ToString() == "0" ? "0" : obj.ToString();
}
cs page_load里面
//分页控件赋值
AspNetPager1.RecordCount = int.Parse(BLLNew.admin_GetCount_S());
sql存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE [dbo].[NewPage_S]
(@startIndex INT,
@endIndex INT
)
AS
begin
WITH NewPageTab AS (
SELECT ROW_NUMBER() OVER (ORDER BY [NewID] desc)AS Row,[NewID],NewTitle,NewSource,NewKeywords,NewDescription,NewAbstract,NewText,NewTime
from New)
SELECT [NewID],NewTitle,NewSource,NewKeywords,NewDescription,NewAbstract,NewText,NewTime
FROM NewPageTab
WHERE Row between @startIndex and @endIndex
end
都按照位置写好 然后绑定aspnetpager就行了...
展开全部
要demo我发一个给你。我那时刚刚学的时候写的,不一定要存储过程。存储过程虽然优势很大,但是灵活性不高,现在很多时候在.NET中用ORM框架是很不错的就比如Nhibernate
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把取到的dataset放到pagedatasource中然后在分页
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询