分页存储过程的问题-->这次80全散了 兄弟门也速战速决吧!!
错误:对象名 '@TableName ' 无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: 对象名 '@TableName ' 无效。
------------------------------
存储过程:
CREATE PROCEDURE dbo.Page_Two
@TableName varchar(20),
@KeyName varchar(20),
@PageIndex int,
@PageSize int,
@TotalRecords int output
AS
BEGIN
-- Set the page bounds
DECLARE @PageLowerBound int
DECLARE @PageUpperBound int
SET @PageLowerBound = @PageSize * (@PageIndex-1)
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsres
(
IndexId int IDENTITY (1, 1) NOT NULL primary key,
UsreId int
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsres (UsreId)
SELECT [KeyName] from [@TableName]
SELECT @TotalRecords = ceiling(@@ROWCOUNT/1.00/@PageSize)
SELECT u.name,u.age
FROM @TableName as u,#PageIndexForUsres as p
WHERE u.[KeyName] = p.UsreId AND
p.IndexId > = @PageLowerBound AND p.IndexId <= @PageUpperBound
RETURN @TotalRecords
END
-----------------------------
Code:
public partial class _Default : System.Web.UI.Page
{
public int pageIndex = 3;
public int pageSize = 10;
public int TotalRecords;//页数
public string tableName = "UsreInfo ";//表名
public string columnName = "uid ";//关联列
protected void Page_Load(object sender, EventAr