Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2006, 01:30 AM
Authorized User
 
Join Date: Apr 2006
Location: Stockholm, , Sweden.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default filtering with dates

Hi,

In my opinion, dates + Sql has always been a complicated couple. (You'd better not have any dates with Sql!) :-)

I have been working with the filterexpression feature of Asp.Net 2.0, and it works really well until I throw in a date. My object here is to only display records within the user-specified dates.

Here's my code (Asp.Net 2.0, VWD Express, VB):


<asp:SqlDataSource ID="VerSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:mydbConnectionString %>"


   SelectCommand="SELECT person.verid, person.fid, person.serie, person.vnr, person.datum, person.vtext, person.sign, person.med, product.vpostid, product.verid AS Expr1, product.kpnr, product.drt, product.krt, product.ptext, product.kst, product.projekt, kpstandard.kpid, kpstandard.kpnr AS Expr2, kpstandard.kpnamn, kpstandard.kptyp FROM person INNER JOIN product ON person.verid = product.verid INNER JOIN kpstandard ON product.kpnr = kpstandard.kpnr WHERE (person.fid = @fid) ORDER BY product.kpnr, person.datum, person.serie, person.vnr"

   EnableCaching="True" CacheDuration="3600"

   FilterExpression="datum >= '{0}' AND datum <= '{1}' ">

   <SelectParameters>

      <asp:SessionParameter DefaultValue="1" Name="fid" SessionField="fid" Type="Int32" />

   </SelectParameters>

   <FilterParameters>

      <asp:ControlParameter Name="fromdatum" ControlID="FromdatumHiddenField" PropertyName="Value" />

      <asp:ControlParameter Name="todatum" ControlID="TodatumHiddenField" PropertyName="Value" />



   </FilterParameters>



</asp:SqlDataSource>
The date in the hiddenfield (which has a date from a textbox, simply formatted in this manner) is formatted like this "2006-06-28", and is set to date with CDate. I have tried both just sending the date as 2006-06-28 and as '2006-06-28' (and I have checked them via response.write). Whatever I do, the filterexpression gets totally omitted - the page works but the date filtering and other filtering as well is disregarded. When I do a response.write of the db's dates they are in the same format: 2006-06-28 00:00 (I've set sv-se - Swedish - in the web.config file). Note that if I only have other filtereing and no dates, it works just fine. Perhaps it has to do with the single hyphens, but I can't figure out how to do it.

Surprisingly, I can't find any posts on this site regarding this matter, using the built-in capabilities of Asp.Net. It's really neat, but I need to get the date issue fixed. Any help is greatly appreciated!

Thanks in advance,

Pettrer

BTW, I ususally write my Select statements myself, but this time I let VWD Express do it for me. It's a bunch of innner joins and much more, as can be seen above, whereas I'd only write SELECT person.name, product.shipped ... FROM person, product, kpstandard... WHERE person.pID = product.pID AND product.sID = kpstandard.sID AND ...

Which way is the best? Is VWD's way faster?

Thanks

P


Coding is indeed a nine-to-five job; nine pm to five am.
__________________
Coding is indeed a nine-to-five job; nine pm to five am.
Reply With Quote
  #2 (permalink)  
Old September 13th, 2007, 01:19 PM
Registered User
 
Join Date: Sep 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I had the same problem with filter expression and solve it reading the VS 2005: "Date values should be enclosed within pound signs (#)".

So, your code must be:

FilterExpression="datum >= #'{0}'# AND datum <= #'{1}'# ">

It works well here.

Att,

Valdeci Jr.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use OR during filtering..... raaj81 Reporting Services 0 July 30th, 2008 05:34 AM
ArrayList Filtering SKhna ASP.NET 2.0 Basics 2 February 11th, 2008 03:30 PM
Filtering a DataGridView furjaw VB.NET 0 November 6th, 2007 02:03 AM
filtering records Vince_421 Access VBA 3 April 2nd, 2007 04:19 PM
Filtering listboxes Bill Snow VB Databases Basics 0 February 5th, 2004 03:32 PM



All times are GMT -4. The time now is 08:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.