我写了一个存储过程实现, 描述:先提取所需记录,插入到临时表,然后判断临时表的记录条数动态加入空记录,最后返回临时表的记录集。 我没有测试,你试试吧 CREATE PROCEDURE dbo.pro_test @Page int,--页数 @PageSize int--每页显示记录条数as declare @temp int declare @temp1 int set @temp=@Page*@PageSize set @temp1=(@Page-1)*@PageSize --创建临时表 Create Table #tempTableNew( tmpID int IDENTITY (1, 1) NOT NULL, ID int, field1 nvarchar (2000) ) --数据载入临时表 exec('INSERT #tempTableNew (ID,field1) select ID,field1 from table1 and ID in (select top '+@temp+' ID from table1 where order by ID DESC) and ID not in (select top '+@temp1+' ID from table1 where order by ID DESC) order by ID DESC') --如果一页数据少于@PageSize,动态添加记录 --根据@@ROWCOUNT处理 if @@ROWCOUNT<@PageSize begin declare @iCount int set @iCount=@@ROWCOUNT while @iCount<@PageSize begin INSERT #tempTableNew (ID,field1) value (0,'') @iCount=@iCount+1 end end
--最终返回记录集 Select tmpID,ID,field1 From #tempTableNew Drop Table #tempTableNew
还不明白? 两个方法,一个在绑定datagrid前,你DATAGRID所绑定的数据集里的数据表加上5个空白列,然后再绑定。比如你个简单的查询吧。原来是select t.id,t.name,t.age from table1 t,你再加几列空的:select t.id,t.name,t.age,'' as 空白1,'' as 空白2 from table1 t另一个方法就是绑定datagrid后,再不满15列的情况下再加几列 datagrid1.Columns.Add("空白") .............................
描述:先提取所需记录,插入到临时表,然后判断临时表的记录条数动态加入空记录,最后返回临时表的记录集。
我没有测试,你试试吧
CREATE PROCEDURE dbo.pro_test
@Page int,--页数
@PageSize int--每页显示记录条数as
declare @temp int
declare @temp1 int
set @temp=@Page*@PageSize
set @temp1=(@Page-1)*@PageSize --创建临时表
Create Table #tempTableNew(
tmpID int IDENTITY (1, 1) NOT NULL,
ID int,
field1 nvarchar (2000)
)
--数据载入临时表
exec('INSERT #tempTableNew (ID,field1) select ID,field1 from table1
and ID in (select top '+@temp+' ID from table1 where order by ID DESC)
and ID not in (select top '+@temp1+' ID from table1 where order by ID DESC)
order by ID DESC')
--如果一页数据少于@PageSize,动态添加记录
--根据@@ROWCOUNT处理
if @@ROWCOUNT<@PageSize
begin
declare @iCount int
set @iCount=@@ROWCOUNT
while @iCount<@PageSize
begin
INSERT #tempTableNew (ID,field1) value (0,'')
@iCount=@iCount+1
end
end
--最终返回记录集
Select tmpID,ID,field1 From #tempTableNew
Drop Table #tempTableNew
两个方法,一个在绑定datagrid前,你DATAGRID所绑定的数据集里的数据表加上5个空白列,然后再绑定。比如你个简单的查询吧。原来是select t.id,t.name,t.age from table1 t,你再加几列空的:select t.id,t.name,t.age,'' as 空白1,'' as 空白2 from table1 t另一个方法就是绑定datagrid后,再不满15列的情况下再加几列
datagrid1.Columns.Add("空白")
.............................