-- myConnection.Open(); -- myDataGrid.DataSource = myCommand.ExecuteReader(); -- myDataGrid.DataBind(); -- myConnection.Close(); -- } -- </Script> -- <html><head><title>DataGrid</title></head><body> -- <form Runat="Server"> -- <asp:DataGrid id="myDataGrid" Runat="Server"/> -- </form> -- </body></html> -- =============================================
IF EXISTS (SELECT name FROM sysobjects WHERE name = N'proTest' AND type = 'P') DROP PROCEDURE proTest GO CREATE PROCEDURE proTest @strSql as nvarchar(2000) = null, --要查询语句如 Select top 30 * from orders @startRow as int = null, --从其开始的从零开始的记录号 @maxRows as int = null --要检索的最大记录数 AS DECLARE @stopRow as int set @stopRow = @startRow + @maxRows
set @strSql = N' Select top ' + CAST(@StopRow as nvarchar(9)) + '*, IDENTITY(int,1,1) AS TempIDKey_Num ' + ' INTO #New_Table ' + ' FROM( ' + @strSql + ') A ' + ' Select * From #New_Table Where TempIDKey_Num>=' + CAST(@StartRow as nvarchar(9)) + ' DROP TABLE #New_Table ' execute sp_executesql @strSql
GO ---------------------------------------------- 这个效率不错。 但是我目前碰到了一些问题,不知道大家有什么好的解决办法。
1、当排序字段为一个以上时,如有如下查询语句: select id, a,b,c from tb where a='aa' order by a,b 即@fldName 为'a,b'时,出错: 列名 'a,b' 无效。
2、当某个表没有ID字段,只有复合主键(如a和b)时,也通不过。
|