Stored procedure using C# and sqlDataReader

Posted on 2004-04-04
Last Modified: 2007-12-19

I posted this question in the Dreamweaver section, but unfortunatley received no reply.

I'm trying to set up paging through a repeater region.
I can do it using a sql statement, but the books I have briefly touch on stored procedures.

As this is custom code, Dreamweaver does not create the code for you and as a result i'm stuck.

I have supplied the code below for the repeater region and paging. Could anyone help and create the sqlDataReader so that I can complete this page. Database is SQL2000

<script runat="server">
string FirstWord, SecondWord, ThirdWord, FourthWord, FifthWord, SixthWord, SeventhWord, QueryPhrase;
PagedDataSource Pager = new PagedDataSource();
void Page_Load(Object Src, EventArgs E)
            Pager.AllowPaging = true;            
            Pager.PageSize = 10;
            Pager.CurrentPageIndex = 0;
      void ChangePage(object sender, System.EventArgs e)
            LinkButton Btn = (LinkButton)sender;
            Pager.CurrentPageIndex = Convert.ToInt32(Btn.CommandArgument);
      void DoDataBinding()

       //Need to change this section to stored procedure

            System.Data.OleDb.OleDbConnection ObjConn;
            System.Data.OleDb.OleDbDataAdapter ObjDa;
            System.Data.DataTable DisplayResults = new System.Data.DataTable();
            ObjConn = new System.Data.OleDb.OleDbConnection("*****");
            ObjDa = new System.Data.OleDb.OleDbDataAdapter("*****, ObjConn);
      //End stored procedure section
      if(Pager.CurrentPageIndex < 0)
                  Pager.CurrentPageIndex = 0;
            Pager.DataSource = DisplayResults.DefaultView;      
            ViewResults.DataSource = Pager;
            lnkFirst.Enabled = Pager.CurrentPageIndex > 0;
            lnkBack.Enabled = Pager.CurrentPageIndex > 0;            
            lnkNext.Enabled = Pager.CurrentPageIndex < (Pager.PageCount - 1);
            lnkLast.Enabled = Pager.CurrentPageIndex < (Pager.PageCount - 1);            
<form name="QueryResults" id="ViewQueryResults" runat="server">
    <ASP:Repeater  ID="ViewResults"  runat="server">
      <ItemTemplate><br><br><strong>Name:</strong>&nbsp;<%# DataBinder.Eval(Container.DataItem, "name") %><br>
        <strong>Address:</strong>&nbsp;<%# DataBinder.Eval(Container.DataItem, "Address") %>
            <asp:LinkButton ID="lnkFirst" Text="First" CommandArgument="0" OnClick="ChangePage" runat="server"></asp:LinkButton>
            <asp:LinkButton Text="Next" CommandArgument="<%# Pager.CurrentPageIndex + 1 %>" OnClick="ChangePage" runat="server" ID="lnkNext"></asp:LinkButton>
            <asp:LinkButton Text="Back" CommandArgument="<%# Pager.CurrentPageIndex - 1 %>" OnClick="ChangePage" runat="server" ID="lnkBack"></asp:LinkButton>
            <asp:LinkButton Text="Last" CommandArgument="<%# Pager.PageCount - 1 %>" OnClick="ChangePage" runat="server" ID="lnkLast"></asp:LinkButton>
             Page <%# Pager.CurrentPageIndex + 1 %> Of <%# Pager.PageCount %>

The stored procedure takes the following parameters.

<Parameter  Name="@QueryPhrase"  Value='<%# ((Request.QueryString["Query"] != null) && (Request.QueryString["Query"].Length > 0)) ? Request.QueryString["Query"] : "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@WordOne"  Value='<%# (FirstWord  != "") ? FirstWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@WordTwo"  Value='<%# (SecondWord  != "") ? SecondWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@Wordthree"  Value='<%# (ThirdWord  != "") ? ThirdWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@Wordfour"  Value='<%# (FourthWord  != "") ? FourthWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@Wordfive"  Value='<%# (FifthWord  != "") ? FifthWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  
    <Parameter  Name="@Wordsix"  Value='<%# (SixthWord  != "") ? SixthWord :  "Default Value"    %>'  Type="VarChar"  Size="100"  Direction="Input" />  

Any help would be appreciated.
Question by:Tourist_Search
1 Comment

Accepted Solution

glsac earned 500 total points
ID: 10754091
Bec. I am to lazy to retype :) here is code for custom paging and the sproc used in a repeater:

I posted this a while back.


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now