我的过程返回 25 行。我DataContext
在调试模式下运行时看到了它。但是在数据绑定后,gridview 没有显示任何内容。当我将select
条款更改为
Select *
from pgnchess
order by GameID
OFFSET @Offset ROW
FETCH NEXT @PageSize ROW ONLY
一切都好。当我在没有任何参数的 SQL Server Management Studio 中执行过程时,也运行得很好。
这是我的 SQL Server 过程
CREATE PROCEDURE [dbo].[GetGamesWithPlayer](
@qText nvarchar(40) = '%',
@qColumn nvarchar(10) = 'BlackWhite',
@orderColumn nvarchar(20) = 'GameID',
@orderDirection bit = 1,
@PageSize int = 25,
@CurrentPage int = 0)
AS
BEGIN
DECLARE @Offset int;
SET NOCOUNT ON;
SET @Offset = @PageSize * @CurrentPage
SELECT
[GameID], [Event], [Site], [Date], [White], [Black], [Result], [ECO]
FROM
[dbo].[pgnGames]
WHERE
CASE @qColumn
WHEN 'BlackWhite' THEN [Black]
WHEN 'Event' THEN [Event]
WHEN 'Black' THEN [Black]
WHEN 'White' THEN [White]
WHEN 'ECO' THEN [ECO]
WHEN 'Result' THEN [Result]
END LIKE '%'+ @qText +'%' OR
CASE @qColumn
WHEN 'BlackWhite' THEN [White]
WHEN 'Event' THEN [Event]
WHEN 'Black' THEN [Black]
WHEN 'White' THEN [White]
WHEN 'ECO' THEN [ECO]
WHEN 'Result' THEN [Result]
END LIKE '%'+ @qText +'%'
ORDER BY
CASE WHEN @orderColumn = 'Black'
AND @orderDirection = 0 THEN [Black] END DESC,
CASE WHEN @orderColumn = 'Black'
AND @orderDirection = 1 THEN [Black] END,
CASE WHEN @orderColumn = 'Date'
AND @orderDirection = 0 THEN [Date] END DESC,
CASE WHEN @orderColumn = 'Date'
AND @orderDirection = 1 THEN [Date] END,
CASE WHEN @orderColumn = 'ECO' AND @orderDirection = 0 THEN [ECO] END DESC,
CASE WHEN @orderColumn = 'ECO' AND @orderDirection = 1 THEN [ECO] END,
CASE WHEN @orderColumn = 'Event' AND @orderDirection = 0 THEN [Event] END DESC,
CASE WHEN @orderColumn = 'Event' AND @orderDirection = 1 THEN [Event] END,
CASE WHEN @orderColumn = 'GameID' AND @orderDirection = 0 THEN [GameID] END DESC,
CASE WHEN @orderColumn = 'GameID' AND @orderDirection = 1 THEN [GameID] END,
CASE WHEN @orderColumn = 'Result' AND @orderDirection = 0 THEN [Result] END DESC,
CASE WHEN @orderColumn = 'Result' AND @orderDirection = 1 THEN [Result] END,
CASE WHEN @orderColumn = 'Site' AND @orderDirection = 0 THEN [Site] END DESC,
CASE WHEN @orderColumn = 'Site' AND @orderDirection = 1 THEN [Site] END,
CASE WHEN @orderColumn = 'White' AND @orderDirection = 0 THEN [White] END DESC,
CASE WHEN @orderColumn = 'White' AND @orderDirection = 1 THEN [White] END
OFFSET @Offset ROW
FETCH NEXT @PageSize ROW ONLY
END
GO
这是我的绑定代码:
DateTime startTime = DateTime.Now;
pgDataContext pl = new pgDataContext();
GameList.DataSource = pl.GetGamesWithPlayer(hdr.qText,hdr.qColumn,GlobalVar.sortColumn,GlobalVar.sortOrder, GlobalVar.pageSize, pgIndex);
GameList.DataBind();
recordCount = pl.pgnGames.Count();
GameList.VirtualItemCount = recordCount;
DateTime endTime = DateTime.Now;
TimeSpan span = endTime.Subtract(startTime);