V
Vitamin
I have written a stored procedure which will paging the recordset, and
return a range of record that i need, and i write a asp code to call it
however, no any return after the set objRs = objCmd.Execute
when i try to Response.write (objRs.recordcount)
it said the recordset is close....
how can i solve this problem?? thx
====================
Here is my stored procedure
====================
CREATE PROCEDURE sp_admin_member_searching
@request_page INT = 1,
@page_size INT = 0,
@id INT = 0,
@membership_id INT = 0,
@area_id INT = 0,
@return_page INT = 0 OUTPUT,
@total_records INT = 0 OUTPUT,
@total_pages INT = 0 OUTPUT
AS
BEGIN
DECLARE
@sql_request NVARCHAR(4000)
-- create temp table to store all member information
CREATE TABLE #temp(
record_id INT IDENTITY(1, 1),
id INT,
membership_id INT,
Company_name_tc NVARCHAR(50),
Company_name_en CHAR(100),
register_date DATETIME
)
-- initial sql statement to insert company record to temp table
SET @sql_request = N'INSERT INTO #temp (id, membership_id, Company_name_tc,
Company_name_en, register_date) '
SET @sql_request = @sql_request + N'SELECT id, membership_id,
company_name_tc, company_name_en, register_date FROM tblCompanyInformation '
SET @sql_request = @sql_request + N'WHERE 1 = 1 '
-- determine user have provide id or not
IF @id > 0 SET @sql_request = @sql_request + N'AND id = ' + CAST(@id AS
NVARCHAR) + ' '
-- determine user have provide membership id or not
IF @membership_id <> '' SET @sql_request = @sql_request + N'AND
membership_id = ' + CAST(@membership_id AS NVARCHAR) + ' '
-- determine user have provide area id or not
IF @area_id <> '' SET @sql_request = @sql_request + N'AND area_id = ' +
CAST(@area_id AS NVARCHAR) + ' '
SET @sql_request = @sql_request + N'ORDER BY id ASC'
-- execute insert record statement
EXECUTE sp_executesql @sql_request
-- get total records count
SET @total_records = @@ROWCOUNT
-- get total page
SET @total_pages = @total_records / @page_size
IF (@total_records % @page_size) <> 0 SET @total_pages = @total_pages + 1
-- set current page position
IF @request_page > @total_pages
SET @request_page = 1
ELSE IF @request_page < 1
SET @request_page = @total_pages
-- return the next page number
SET @return_page = @request_page
-- initial sql statement to paging the result
IF @request_page = 1
BEGIN
SELECT id, membership_id, Company_name_tc, Company_name_en, register_date
FROM #temp
WHERE record_id >= ((@request_page - 1) * @page_size) AND record_id <=
(@request_page * @page_size)
ORDER BY Company_name_en ASC
END
ELSE
BEGIN
SELECT id, membership_id, Company_name_tc, Company_name_en, register_date
FROM #temp
WHERE record_id >= (((@request_page - 1) * @page_size) + 1) AND record_id
<= (@request_page * @page_size)
ORDER BY Company_name_en ASC
END
DROP TABLE #temp
END
====================
here is my ASP code
====================
dim objCn, objRs, objCmd, objParam
dim iPageSize, iTotalRecords, iTotalPages, iPage
set objCn = getConnection ()
set objCmd = getCommand(objCn, "sp_admin_member_searching", 4, true)
iPageSize = 10
iTotalRecords = 0
iTotalPage = 0
'@ determine command parameter
set objParam = objCmd.createParameter ("request_page", 3, 1,
request("page"))
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("page_size", 3, 1, iPageSize)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("membership_id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("area_id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("return_page", 3, 2, iPage)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("total_records", 3, 2,
iTotalRecords)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("total_pages", 3, 2,
iTotalPages)
objCmd.Parameters.append objParam
set objRs = objCmd.execute
releaseDataObject (objCmd)
releaseDataObject (objRs)
releaseDataObject (objCn)
return a range of record that i need, and i write a asp code to call it
however, no any return after the set objRs = objCmd.Execute
when i try to Response.write (objRs.recordcount)
it said the recordset is close....
how can i solve this problem?? thx
====================
Here is my stored procedure
====================
CREATE PROCEDURE sp_admin_member_searching
@request_page INT = 1,
@page_size INT = 0,
@id INT = 0,
@membership_id INT = 0,
@area_id INT = 0,
@return_page INT = 0 OUTPUT,
@total_records INT = 0 OUTPUT,
@total_pages INT = 0 OUTPUT
AS
BEGIN
DECLARE
@sql_request NVARCHAR(4000)
-- create temp table to store all member information
CREATE TABLE #temp(
record_id INT IDENTITY(1, 1),
id INT,
membership_id INT,
Company_name_tc NVARCHAR(50),
Company_name_en CHAR(100),
register_date DATETIME
)
-- initial sql statement to insert company record to temp table
SET @sql_request = N'INSERT INTO #temp (id, membership_id, Company_name_tc,
Company_name_en, register_date) '
SET @sql_request = @sql_request + N'SELECT id, membership_id,
company_name_tc, company_name_en, register_date FROM tblCompanyInformation '
SET @sql_request = @sql_request + N'WHERE 1 = 1 '
-- determine user have provide id or not
IF @id > 0 SET @sql_request = @sql_request + N'AND id = ' + CAST(@id AS
NVARCHAR) + ' '
-- determine user have provide membership id or not
IF @membership_id <> '' SET @sql_request = @sql_request + N'AND
membership_id = ' + CAST(@membership_id AS NVARCHAR) + ' '
-- determine user have provide area id or not
IF @area_id <> '' SET @sql_request = @sql_request + N'AND area_id = ' +
CAST(@area_id AS NVARCHAR) + ' '
SET @sql_request = @sql_request + N'ORDER BY id ASC'
-- execute insert record statement
EXECUTE sp_executesql @sql_request
-- get total records count
SET @total_records = @@ROWCOUNT
-- get total page
SET @total_pages = @total_records / @page_size
IF (@total_records % @page_size) <> 0 SET @total_pages = @total_pages + 1
-- set current page position
IF @request_page > @total_pages
SET @request_page = 1
ELSE IF @request_page < 1
SET @request_page = @total_pages
-- return the next page number
SET @return_page = @request_page
-- initial sql statement to paging the result
IF @request_page = 1
BEGIN
SELECT id, membership_id, Company_name_tc, Company_name_en, register_date
FROM #temp
WHERE record_id >= ((@request_page - 1) * @page_size) AND record_id <=
(@request_page * @page_size)
ORDER BY Company_name_en ASC
END
ELSE
BEGIN
SELECT id, membership_id, Company_name_tc, Company_name_en, register_date
FROM #temp
WHERE record_id >= (((@request_page - 1) * @page_size) + 1) AND record_id
<= (@request_page * @page_size)
ORDER BY Company_name_en ASC
END
DROP TABLE #temp
END
====================
here is my ASP code
====================
dim objCn, objRs, objCmd, objParam
dim iPageSize, iTotalRecords, iTotalPages, iPage
set objCn = getConnection ()
set objCmd = getCommand(objCn, "sp_admin_member_searching", 4, true)
iPageSize = 10
iTotalRecords = 0
iTotalPage = 0
'@ determine command parameter
set objParam = objCmd.createParameter ("request_page", 3, 1,
request("page"))
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("page_size", 3, 1, iPageSize)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("membership_id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("area_id", 3, 1, 0)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("return_page", 3, 2, iPage)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("total_records", 3, 2,
iTotalRecords)
objCmd.Parameters.append objParam
set objParam = objCmd.createParameter ("total_pages", 3, 2,
iTotalPages)
objCmd.Parameters.append objParam
set objRs = objCmd.execute
releaseDataObject (objCmd)
releaseDataObject (objRs)
releaseDataObject (objCn)