asp:SqlDataSource with parameters

Discussion in 'ASP .Net' started by E. Kwong, Nov 10, 2007.

  1. E. Kwong

    E. Kwong Guest

    I just want to select records with a certain date field > today's date:

    <asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$
    ConnectionStrings:xyz %>"

    SelectCommand="SELECT * FROM [Events] WHERE [Startdate] > ? "
    OnSelected="src1_Selected">

    <SelectParameters>

    <asp:parameter Name="Startdate" Type="DateTime" />

    </SelectParameters>

    </asp:SqlDataSource>

    ---------------------

    protected void srcEvents_Selected(object sender,
    SqlDataSourceStatusEventArgs e)

    {

    e.Command.Parameters["Startdate"].Value = DateTime.Today;

    }

    -------------------

    I have a list control bind to this data source but when executed the list
    doesn't show. That means no record is selected. I know there are
    qualifying records since I input them myself in SQL server.

    Am newbie so I must code something wrong. Any insignt appreciated.
     
    E. Kwong, Nov 10, 2007
    #1
    1. Advertising

  2. The problem is that the Selected event does not occur until *after* data has
    been retrieved from the database. Try setting the parameter in the PageLoad
    handler.

    --
    Robert Dunlop
    ----------------
    http://www.directxzone.org
    http://rdunlop.spaces.live.com/
    Microsoft DirectX MVP 1998-2006

    "E. Kwong" <ekwong999AThotmail.com> wrote in message
    news:...
    >I just want to select records with a certain date field > today's date:
    >
    > <asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$
    > ConnectionStrings:xyz %>"
    >
    > SelectCommand="SELECT * FROM [Events] WHERE [Startdate] > ? "
    > OnSelected="src1_Selected">
    >
    > <SelectParameters>
    >
    > <asp:parameter Name="Startdate" Type="DateTime" />
    >
    > </SelectParameters>
    >
    > </asp:SqlDataSource>
    >
    > ---------------------
    >
    > protected void srcEvents_Selected(object sender,
    > SqlDataSourceStatusEventArgs e)
    >
    > {
    >
    > e.Command.Parameters["Startdate"].Value = DateTime.Today;
    >
    > }
    >
    > -------------------
    >
    > I have a list control bind to this data source but when executed the list
    > doesn't show. That means no record is selected. I know there are
    > qualifying records since I input them myself in SQL server.
    >
    > Am newbie so I must code something wrong. Any insignt appreciated.
    >
    >
    >
    >
     
    Robert Dunlop, Nov 10, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?=

    Modify SqlDataSource parameters before select

    =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?=, Oct 20, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    28,048
    Steven Cheng[MSFT]
    Oct 25, 2005
  2. Replies:
    1
    Views:
    446
    =?Utf-8?B?Sml0ZXNo?=
    Dec 22, 2005
  3. Kees de Winter

    How to access parameters of SqlDataSource

    Kees de Winter, Mar 29, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    5,560
    Kees de Winter
    Mar 29, 2006
  4. =?Utf-8?B?RGFiYmxlcg==?=

    modify SqlDataSource parameters in code behind?

    =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    28,387
    =?Utf-8?B?RGFiYmxlcg==?=
    Apr 4, 2006
  5. =?Utf-8?B?R3JlaWY=?=

    Setting Parameters for SqlDataSource control

    =?Utf-8?B?R3JlaWY=?=, Jun 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    428
    =?Utf-8?B?R3JlaWY=?=
    Jun 23, 2006
Loading...

Share This Page