Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
[Moved from title]
In the below code use only either CustomerID or Customer Name or City.
I want all fields are work in the Gridview.
Please solve them.

SQL
ALTER PROCEDURE [dbo].[GetCustomers_Pager]
       @SearchTerm VARCHAR(100) = ''
      ,@PageIndex INT = 1
      ,@PageSize INT = 10
      ,@RecordCount INT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [CustomerID] ASC
      )AS RowNumber
      ,[CustomerID]
      ,[CompanyName]
      ,[ContactName]
      ,[City]
      INTO #Results
      FROM [Customers]
      WHERE [CustomerID] LIKE @SearchTerm + '%' OR @SearchTerm = ''
      
      SELECT @RecordCount = COUNT(*)
      FROM #Results
          
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
    
      DROP TABLE #Results
END
Posted
Updated 24-Sep-14 18:27pm
v2
Comments
George Jonsson 25-Sep-14 0:30am    
I modified your title as you put most of your question there.
Not sure what problem you need to be solved.
What do you mean by keypress in this context?
Member 10928697 25-Sep-14 0:37am    
keypress mean ..im using gridview a bove search box sir...in the search box iam enter the1st letter like customer id or city or name , display the full customername and city and customer name sir that is keypress event...can i send source code sir.
Member 10928697 25-Sep-14 0:43am    
its working

1 solution

Change it to
SQL
ALTER PROCEDURE [dbo].[GetCustomers_Pager]
       @SearchTerm VARCHAR(100) = ''
      ,@PageIndex INT = 1
      ,@PageSize INT = 10
      ,@RecordCount INT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [CustomerID] ASC
      )AS RowNumber
      ,[CustomerID]
      ,[CompanyName]
      ,[ContactName]
      ,[City]
      INTO #Results
      FROM [Customers]
      WHERE [ContactName] LIKE @SearchTerm + '%' OR [CustomerID] LIKE @SearchTerm + '%' OR [City] LIKE @SearchTerm + '%' OR @SearchTerm = ''
      
      SELECT @RecordCount = COUNT(*)
      FROM #Results
          
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
    
      DROP TABLE #Results
END
 
Share this answer
 
Comments
Member 10928697 25-Sep-14 0:42am    
thanku sir its working....
ChauhanAjay 25-Sep-14 0:48am    
I already provided the solution in your last question http://www.codeproject.com/Questions/821864/Im-using-below-code-for-keypress-searching-in-grid?arn=0
Member 10928697 25-Sep-14 0:51am    
ho sorry i con't see.
MuhammadUSman1 25-Sep-14 1:39am    
Excellent [@ChauhanAjay] +5
ChauhanAjay 25-Sep-14 2:11am    
Thanks MuhammadUSman1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900