473,382 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SP and ADO Page Property Not Working Properly

Hi all...I have a stored proc that works fine except I can't get the
paging property to work in ASP. It seems that because I'm building the
SQL withing the SP is causing the problem. If I don't build the SQL as
a string paging works. In my ASP page, the pagecount property returns
-1 for some reason.

Here's the proc:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER Procedure LS_DisplayAllCategoriesBoolean
@aSections varchar(255),
@field varchar(255)

As

declare @sql varchar(1000)
SET NOCOUNT ON

set @sql = 'SELECT DISTINCT ls_product_catalog.id,
ls_product_catalog.ItemNumber, ls_product_catalog.Name,
ls_product_catalog.[Descriptor], ls_product_catalog.Price,
ls_product_catalog.Shade_Name, ls_product_catalog.Sale_Price,
ls_product_catalog.Sale_Desc
FROM dbo.ls_brand INNER JOIN
dbo.ls_product_catalog ON dbo.ls_brand.nID =
dbo.ls_product_catalog.CategoryID INNER JOIN
dbo.ls_product_category ON dbo.ls_product_catalog.id =
dbo.ls_product_category.nProductID
WHERE dbo.ls_brand.bVisible = 1 and
dbo.ls_product_category.nCategoryID in (Select IntValue
from dbo.CsvToInt(''' + @aSections + ''') ) '

if @field = 'bNew'
begin
set @sql = @sql + ' AND bNew = 1 AND
(dbo.ls_product_catalog.bGiftOnly is null or
dbo.ls_product_catalog.bGiftOnly = 0)'
set @sql = @sql + ' order by
ls_product_catalog.[Descriptor]'
end
if @field = 'bGift'
begin
set @sql = @sql + ' AND bGift = 1 or bGiftOnly =1'
set @sql = @sql + ' order by
ls_product_catalog.[Descriptor]'
end

if @field = 'bGiftOnly'
begin
set @sql = @sql + ' AND bGiftOnly= 1'
set @sql = @sql + ' order by
ls_product_catalog.[Descriptor]'
end

if @field = 'sale_price'
begin
set @sql = @sql + ' AND (sale_price is not null OR
sale_desc is not
null)'
set @sql = @sql + ' order by ls_product_catalog.Name'
end

exec(@sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON

Dec 3 '05 #1
1 1369
(rh******@gmail.com) writes:
Hi all...I have a stored proc that works fine except I can't get the
paging property to work in ASP. It seems that because I'm building the
SQL withing the SP is causing the problem. If I don't build the SQL as
a string paging works. In my ASP page, the pagecount property returns
-1 for some reason.


I don't think the paging stuff in ADO is very effective for paging. It
works (sometimes), but the overhead may be devastative.

Check out Aaron Bertrand's www.aspfaq.com and search for "paging". He
has a few articles about paging where you can find alternatives to what
ADO offers.

In the meanwhile, I can offer suggestions to relieve you from the use
of dynamic SQL. It appears that you use dynamic SQL for two reasons:
1) To handle the comma-separated list 2) to select a field for the search,
and also determine order.

The comma-separated list is simple: unpack it with a table-valued function
and join to that function. I describe several methods in an article on
my web site. To get a head start, go directly to
http://www.sommarskog.se/arrays-in-sql.html#iterative.

The @field parameter requires a little more work, but here is a
possibility:

AND CASE @field
WHEN 'bNew' THEN CASE WHEN bNew = 1 AND
coalesce(pc.bGiftOnly, 0) = 0
THEN 1
ELSE 0
END
WHEN 'bGift' THEN bGift | bGiftOnly
WHEN 'sale_price' THEN CASE WHEN sale_price IS NOT NULL OR
sale_desc IS NOT NULL
THEN 1
ELSE 0
END
ELSE 1
END = 1
ORDER BY CASE @field
WHEN 'sale_price' THEN ls_product_catalog.Name
ELSE ls_product_catalog.[Descriptor]
END

I'm here using the CASE *expression* to handle the dynamic stuff with
@field. Note the emphasis on expression, this is different from many
other languages. An expression must return a value, and you cannot return
a value like "a = 0", as SQL does not have a boolean data type. But for
every check, you can fork of yet another CASE expression. For bGift, as
you can see, I was able to skip the CASE, by using the fairly obscure
bitwise OR operator.

A CASE expression always returns the one and same data type. If different
branches returns different data types, there will be conversion to the
type that is highest in SQL Servers data-type precedence order.

For details on syntax, please see Books Online.

While the above is neat, I should add that it is not always a feasible
solution. Your solution with dynamic SQL has the advantage of including
only what is at hand for the current search. If the alternatives includes
indexed columns, performance is likely to suffer if you include all possible
alternatives. But it does not seems to me that this should be the case
here.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 3 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: The Eternal Squire | last post by:
Hi everyone, I am wanting to write a Python COM server with a data member created by using the new Python 2.3 property() built-in function. When I attempt to access the member through a...
3
by: Dave McCracken | last post by:
I am hosting .Net UserControls in HTML pages with Object Tags. These UserControls are clients of remotable objects that run on the same machine. The remote objects execute callbacks via sponsor...
1
by: Malkalypse | last post by:
Hello, I have been having some trouble with this one, so I decided to strip it down to its simplest form. I think I found the root of the problem, but I don't know how to solve it. I need a link...
0
by: myPosts | last post by:
Hi all, I am having problem at a time of using datagrid in c#.net. On currentcell change event of datagrid i am displaying one combobox and setting location of combobox depending on location...
3
by: retsam | last post by:
All, I'm working on an ASP.NET 2.0 (C#) page and have a question on how to build a string that includes line feeds (new lines) that displays properly on an ASP.NET page. Here's what I got: ...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
3
by: Mukesh | last post by:
Hi all I have to transfer a dataset and a string from a webform to a user control on the page without using viewstate or session or cookies . properties method is not working properly. if...
0
by: robgallen | last post by:
I have 2 user controls within a master page, and I would like one of them to call a function in the other. All the examples I have seen involve a page communicating with the Master page, or with...
4
by: BillE | last post by:
Using VS2005, C#, asp 2, web forms I have a panel which contains 3 sub-panels. The first sub-panel contains a combo box. Making a selection populates a gridview in the second sub-panel. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.