I have a stored procedure that uses the SQL Server technique for paging. It creates a temporary table of all of the results and then queries that temp table to filter out the amount of rows specified on the correct page. The sproc returns rows when run in query analyzer, but if I try to get a recordset in a VB6 component (w/MDAC 2.6 SP1), I get an ADO error stating that the recordset is closed.We have experienced this problem in the past and have found no real fix for it. Is there a bug somewhere? I can guarantee that my ADO code and my sproc code is correct.The sproc is below. It has been edited to remove transactions and error checking. It's down to the basic function of the sproc.CREATE PROCEDURE KeywordSearchResults_Gen_Vend/* Name: KeywordSearchResults_Gen_Vend Description: This sproc returns a list of parts based on generic description chosen and current page. It sorts by Vendor, Part Number ASCENDING. Author: Michael Sumerano Date: 01/25/2002*/@BlanketMargin decimal(6,3),@Warehouse int,@AltWarehouse int,@CustNo int,@GenKey int,@page int,@size int,@pagecount int OUTPUTASdeclare @start int, @end int --Calculate the starting Row SET @Start = (((@Page - 1) * @Size) + 1) --Calculate the ending Row SET @End = (@Start + @Size - 1) --Create temporary table to store all results from search CREATE TABLE #FullResults ( Row int IDENTITY(1,1) PRIMARY KEY, InvKey int, VendNum char(3), VendorName char(12), PartNum char(25), [Description] char(25), RetailPrice money, JobberPrice money, CorePrice money, FederalExciseTax money, PriceCode bit, OnHand int, AltInventory int, SpecialOrder bit, Reference bit ) --Insert all results from search INSERT INTO #FullResults SELECT DISTINCT Inv.InvKey, inv.VendNum, Ven.VendorName, Inv.PartNum, Inv.[Description], jobberprice / (1 - ISNULL((markup), @BlanketMargin) / 100) AS RetailPrice, Inv.jobberprice, Inv.corePrice, Inv.federalExciseTax, Inv.PriceCode, boh.onHand, alt.onHand as AltInventory, Inv.SpecialOrder, NULLIF(ISNUMERIC(ref.refkey), 0) as Reference FROM dbo.Inventory inv INNER JOIN dbo.Vendor ven ON Inv.VenKey = Ven.VenKey LEFT OUTER JOIN dbo.reference ref ON inv.invkey = ref.invkey LEFT OUTER JOIN dbo.OnHand boh ON Inv.InvKey = boh.InvKey and boh.warehouse = 1 LEFT OUTER JOIN dbo.OnHand alt ON Inv.InvKey = alt.InvKey and alt.warehouse = 1 LEFT OUTER JOIN dbo.Markup mu ON mu.vendornum = ven.vendornum and mu.CustomerNumber = 9400 WHERE inv.invkey in (select DISTINCT invkey from dbo.accessory where gennum = @GenKey) ORDER BY ven.vendorname, inv.partnum --Calculate the page count set @pagecount = CEILING(@@ROWCOUNT / cast(@size as numeric(5,3))) --Select the search results based on the current page SELECT InvKey, VendNum, VendorName, PartNum, [Description], RetailPrice, JobberPrice, CorePrice, FederalExciseTax, PriceCode, OnHand, AltInventory, SpecialOrder, Reference FROM #FullResults WHERE (Row >= @Start) AND (Row <= @End)GO
Michael SumeranoTechnical Web AdministratoreKeystone.comhttp://www.ekeystone.com/