通过DataSet绑定多个表的例子
来源:互联网 发布:linux系统种类 编辑:程序博客网 时间:2024/05/21 14:10
相关存储过程:
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE procedure [dbo].[sp_PageChange]
@PageIndex INT,
@PageSize INT,
@RecordCount INT OUT,
@PageCount INT OUT,
@strGetFields nvarchar(1000),
@tableName nvarchar(500) ,
@ID nvarchar(100),
@strWhere nvarchar(1000) ='',
@sortName nvarchar(50) =' asc ' ,
@orderName nvarchar(100)
AS
declare @countSelect nvarchar(2000)
--设置统计查询语句
if len(@strWhere) =0
--如果没有查询条件
begin
set @countSelect=N'SELECT @CountRecord = COUNT(*) FROM '+@tableName
end
else
--否则
begin
set @countSelect=N'SELECT @CountRecord = COUNT(*) FROM '+@tableName+' where '+@strWhere
end
--执行并返回总数
exec sp_executesql @countSelect,N'@CountRecord int output',@RecordCount output
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
SET NOCOUNT ON
DECLARE @SQLSTR NVARCHAR(3000)
--实际总共的页码小于当前页码 或者 最大页码
if @PageCount>=0
--如果分页后页数大于0
begin
if @PageCount<=@PageIndex and @PageCount>0 --如果实际总共的页数小于datagrid索引的页数
--or @PageCount=1
begin
--设置为最后一页
set @PageIndex=@PageCount-1
end
else if @PageCount<=@PageIndex and @PageCount=0
begin
set @PageIndex=0;
end
end
--如果用普通的sql而不使用存储过程调用
declare @ID_temp varchar(100)
set @ID_temp='cast('+@ID+' as nvarchar(100)) '
declare @returnValue nvarchar(100)
set @returnValue=','''+cast(@RecordCount as nvarchar(100)) +'|'+cast(@PageCount as nvarchar(100))+'|'+'''+'+@ID_temp+' as [returnValue] '
--如果用普通的sql而不使用存储过程调用
IF @PageIndex = 0 OR @PageCount <= 1 --如果为第一页
begin
if len(@strWhere) =0
begin
SET @SQLSTR =N'SELECT TOP '+STR( @PageSize )+@strGetFields+@returnValue+' FROM '+@tableName+' ORDER BY '+@orderName+@sortName
end
else
begin
SET @SQLSTR =N'SELECT TOP '+STR( @PageSize )+@strGetFields+@returnValue+' FROM '+@tableName+' where '+@strWhere+' ORDER BY '+@orderName+@sortName
end
end
ELSE IF @PageIndex = @PageCount - 1 --如果为最后一页
begin
if len(@strWhere) =0
begin
SET @SQLSTR =N' SELECT '+@strGetFields+@returnValue+' FROM '+@tableName+' where '+@ID+' not in ( SELECT TOP '+STR(/*@RecordCount - */@PageSize * @PageIndex )+@ID+' FROM '+@tableName+' ORDER BY '+@orderName+@sortName+' ) ORDER BY '+@orderName+@sortName
end
else
begin
SET @SQLSTR =N' SELECT '+@strGetFields+@returnValue+' FROM '+@tableName+' where '+@ID+' not in ( SELECT TOP '+STR(/*@RecordCount - */ @PageSize * @PageIndex )+@ID+' FROM '+@tableName+' where '+@strWhere+' ORDER BY '+@orderName+@sortName+' ) and '+@strWhere+' ORDER BY '+@orderName+@sortName
end
end
ELSE --否则执行
begin
if len(@strWhere) =0
begin
SET @SQLSTR =N' SELECT TOP '+STR( @PageSize )+@strGetFields+@returnValue+' FROM '+@tableName+' where '+@ID+' not in ( SELECT TOP '+STR( /*@RecordCount - */@PageSize * @PageIndex )+' '+@ID+' FROM '+@tableName+' ORDER BY '+@orderName+@sortName+' ) ORDER BY '+@orderName+@sortName
end
else
begin
SET @SQLSTR =N' SELECT TOP '+STR( @PageSize )+@strGetFields+@returnValue+' FROM '+@tableName+' where '+@ID+' not in (SELECT TOP '+STR(/*@RecordCount - */ @PageSize * @PageIndex )+@ID+' FROM '+@tableName+' where '+@strWhere+' ORDER BY '+@orderName+@sortName+' )and '+@strWhere+'ORDER BY '+@orderName+@sortName
end
end
EXEC (@SQLSTR)
set nocount off
GO
CREATE PROCEDURE sp_Get_FS
AS
BEGIN
execute sp_PageChange 0,12,0,0,'*','[SXGGW]','id','yesno=1',' addtime desc',''
execute sp_PageChange 1,12,0,0,'*','[SXGGW]','id','yesno=1',' addtime desc',''
execute sp_PageChange 2,12,0,0,'*','[SXGGW]','id','yesno=1',' addtime desc',''
execute sp_PageChange 3,12,0,0,'*','[SXGGW]','id','yesno=1',' addtime desc',''
END
GO
页面代码:
SqlDataAdapter adpt = new SqlDataAdapter("sp_Get_FS", ConfigurationManager.AppSettings["ConnectionString"]);
DataSet ds = new DataSet();
adpt.Fill(ds, "talbe");
dl_list1.DataSource = ds.Tables[0];
dl_list1.DataBind();
dl_list2.DataSource = ds.Tables[1];
dl_list2.DataBind();
dl_list3.DataSource = ds.Tables[2];
dl_list3.DataBind();
dl_list4.DataSource = ds.Tables[3];
dl_list4.DataBind();
- 通过DataSet绑定多个表的例子
- 解决分页的例子。使用DataSet绑定到DataList实现的
- 绑定dataset
- 解决分页的例子。使用DataSet绑定到DataList实现的。数据库使用我刚才贴的这个。
- 通过SqlDataSource返回的DataSet
- 类绑定的例子
- 数据绑定的例子
- 动态绑定的例子
- 一个水晶报表绑定DataSet的实例
- DataSet的应用(与GridView绑定)
- c# dataset 和DataGridView的绑定详细
- ASP.NET 绑定DataSet中的多个表
- dataset的relation和遍历小例子
- Excel转DataSet的一个例子
- 一个通过DataSet操作XML的类
- 一个通过DataSet操作XML的类
- 通过DataSet读取XML的效率问题
- 通过DataSet读取XML的效率问题
- VRML资源网址大全
- 用asp生成rss
- gridview模板列绑定gridview
- 使用JNDI进行高级DNS查询
- 小百合十大启示帖
- 通过DataSet绑定多个表的例子
- 收藏
- 最近几天的批量确认的Tuning的经历(一)
- zxcz
- displaytag
- socket编程原理
- 这周一个ORACLE问题的解决过程(ORA-12560:TNS:协议适配器错误! )
- 启动Oracle常见疑难问题分析
- 一件事,一段话...好好想想么