473,385 Members | 1,409 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,385 software developers and data experts.

SQL Paging with VS2005

I don't know why All my stored Procedure which provide custom pageing don't
work in .Net 2..
First i was using Procedures genrated by CodeSmith and N-Tier.. which create
#temp table with auto identity..
But When i create a dataset it parse my procedure uncorrectly and genrate
sqlexception in runtime even it work fine in Managment Studio..

So i tried to create my own Paging using dynamic SQL

CREATE PROCEDURE [dbo].[GetPagedResult]
-- Add the parameters for the stored procedure here
(
@TableName varchar (20),
@ColumnNamesCollection varchar (200) = '*',
@PageIndex int = 0,
@PageSize int = 5,
@WhereCriteria varchar (200) = NULL,
@SortExpression varchar (200) = NULL
)
AS
BEGIN
DECLARE @WHEREWord varchar (20)
DECLARE @ANDWord varchar (20)
DECLARE @OrderBy varchar (20)
DECLARE @IgnoredRows int
SET @IgnoredRows = @PageSize * @PageIndex
-- Check Where Expression
IF @WhereCriteria != NULL AND @WhereCriteria != ''
Begin
SET @WHEREWord = ' WHERE '
SET @ANDWord = ' AND '
End
ELSE
Begin
SET @WHEREWord = ''
SET @ANDWord = ''
End
-- Check Sorting Expression
IF @SortExpression != NULL AND @SortExpression != ''
SET @OrderBy = ','
ELSE
SET @OrderBy = ''
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- SET NOCOUNT ON;
-- Insert statements for procedure here
IF @PageIndex != 0
Begin
EXEC('SELECT TOP '+ @PageSize + ' ' + @ColumnNamesCollection + ' FROM ' +
@TableName + ' WHERE ID NOT IN ( SELECT TOP '+ @IgnoredRows +
' ID FROM ' + @TableName + ' ' + @WHEREWord + ' ' + @WhereCriteria +
' ORDER BY ID ' + @OrderBy + ' ' + @SortExpression + ' ) ' + @ANDWord + ' '
+
@WhereCriteria + ' ORDER BY ID ' + @OrderBy + ' ' + @SortExpression
)
RETURN @@ROWCOUNT
END
Else
Begin
EXEC('SELECT TOP '+ @PageSize + ' ' + @ColumnNamesCollection + ' FROM ' +
@TableName + ' ' + @WHEREWord + ' ' + @WhereCriteria +
' ' + @OrderBy + ' ' + @SortExpression
)
RETURN @@ROWCOUNT
END
END

but it didn't work also for some reason(!!) and it work fine in sql
managment studio too...
So what's wrong in Dynamic storedprocedure?? why dataset can't work with
them??
May 7 '06 #1
1 1012
"Islamegy®" <Is******@Private.4me> wrote in message
news:eb**************@TK2MSFTNGP03.phx.gbl...
but it didn't work also for some reason(!!)


1) How do you know it didn't work?

2) What error did you get?
May 7 '06 #2

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

Similar topics

4
by: Paul Hale | last post by:
Hi, Currently using VS2005 c# Scenario: I have a gridview control displaying many items with paging enabled. Column is a checkbox column which users can check, but when the gridview is paged to...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
1
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the...
2
by: farhad13841384 | last post by:
Hi , I Hope You fine. I have some problem with this code for paging in asp.net this bottom code work correctly without any error but when I try to place separate code in .VB file then error is...
0
by: mvisnich | last post by:
Hi, I am working in VS2005 (VB) environment and I have following problem: On one of my web pages I use Datagrid control which I dynamically load. I also use numerical paging with Datagrid....
0
by: Chris S | last post by:
I'm using the WAP add-on for VS2005, and I keep my static methods (which crank out DataSets for GridViews), within a "DataAccess" folder. There is no "app_Code" folder. It seems like VS2005...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
2
by: ami | last post by:
In my code, I need to implement x numbers of Gridviews dynamically based on user selection. Because I am unaware of the number of gridviews, this is done after the user enters input. I need to...
1
by: =?Utf-8?B?U0FM?= | last post by:
How do I create paging in an ASP.net/C# application that has HTML tables on it? Server side scripting calls C# functions that populate the HTML cells for those tables. Basically, the page is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.