Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hi all, im trying to search data in my MySQL database by date range from 2 textboxes (ie "tbStartDate", "tbEndDate"), but the user must only be allowed to search up to a maximum of only 31 days anything over that a error must be thrown, I have a query that retrieves all the information shown below but now need that date range search from a button click to show only certain record please help
 
("SELECT transactions.transaction_id, transactions.date_time, transaction_type.transaction_type_description, transactions.amount FROM `transactions`" +
        "INNER JOIN transaction_type ON transaction_type.transaction_type_id = transactions.transaction_type_id INNER JOIN member_detail ON member_detail.member_id = transactions.account_or_member_id " +
        "WHERE account_or_member_id = @member_id and is_member = '1' and transactions.transaction_type_id = '5' " +
        "Order by transactions.date_time ASC",con2)
 
any help would be appreciated, been battling with this function.
Wes
Posted 3-Oct-12 20:50pm
Wes101392
Comments
VijayChauhan123 at 4-Oct-12 1:59am
   
Count the difference of the dates based on the result you can execute the query.Use built in datetime function for finding the difference.
Venkatesh Mookkan at 4-Oct-12 2:18am
   
Why can't you restrict the TextBox to have the validation of 31 days and pass the selected dates to the query?
Wes101 at 4-Oct-12 3:12am
   
thanks it worked im retrieving data between whatever dates i choose only, but now im stuck on how to limit it only to 31 days if it more than 31 days a message box must pop up and say something like "Choose 31 days or less"

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DateTime dt = Convert.ToDateTime(tbstartdate.Text))
DateTime dta = Convert.ToDateTime(tbenddate.Text))
TimeSpan pp = dta - dt
Integer days = pp.Days
 
if (days > 31)
{
messegebox.show("U can Not Have More Than 31 days")
return
}
 

("SELECT transactions.transaction_id, transactions.date_time, transaction_type.transaction_type_description, transactions.amount FROM `transactions`" +
        "INNER JOIN transaction_type ON transaction_type.transaction_type_id = transactions.transaction_type_id INNER JOIN member_detail ON member_detail.member_id = transactions.account_or_member_id " +
        "WHERE account_or_member_id = @member_id and is_member = '1' and  transactions.date_time > = @tbstartdate and transactions.date_time <=  @tbenddate and @tbtransactions.transaction_type_id = '5' " +
        "Order by transactions.date_time ASC",con2)
  Permalink  
Comments
Wes101 at 4-Oct-12 4:44am
   
thanks, it worked perfectly, appreciated alot
vijay bisht at 4-Oct-12 4:55am
   
Ur Welcome :)

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

  Print Answers RSS
0 DamithSL 390
1 Maciej Los 217
2 OriginalGriff 213
3 BillWoodruff 130
4 Garth J Lancaster 90
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100