Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > asp:SqlDataSource with parameters

Reply
Thread Tools

asp:SqlDataSource with parameters

 
 
E. Kwong
Guest
Posts: n/a
 
      11-10-2007
I just want to select records with a certain date field > today's date:

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

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

<SelectParameters>

<asparameter 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.




 
Reply With Quote
 
 
 
 
Robert Dunlop
Guest
Posts: n/a
 
      11-10-2007
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:(E-Mail Removed)...
>I just want to select records with a certain date field > today's date:
>
> <asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$
> ConnectionStringsyz %>"
>
> SelectCommand="SELECT * FROM [Events] WHERE [Startdate] > ? "
> OnSelected="src1_Selected">
>
> <SelectParameters>
>
> <asparameter 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.
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
skipping template parameters inside template parameters kito C++ 2 09-26-2010 12:04 AM
Class Member Data and Member Function Parameters - Should Parameters Be Data Members? Jason C++ 2 05-13-2006 07:11 AM
commands to configure WLAN adapter parameters =?Utf-8?B?SmFnYW4=?= Wireless Networking 0 10-05-2005 11:37 AM
does a "parameters"-parameter overwrite the "parameters"-object? Florian Loitsch Javascript 11 03-15-2005 03:33 PM
Servlet parameters different from the command line parameters? Jonck van der Kogel Java 2 05-26-2004 11:34 PM



Advertisments