Fetching records based on range of dates

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 3
Reputation: dhana3 is an unknown quantity at this point 
Solved Threads: 0
dhana3 dhana3 is offline Offline
Newbie Poster

Fetching records based on range of dates

 
0
  #1
25 Days Ago
Hai,
I need to fetch records in to gridview based on fromdate and todate using c#,plzzz help asap
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 920
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 147
DdoubleD DdoubleD is offline Offline
Posting Shark
 
0
  #2
24 Days Ago
Are you wanting a WHERE clause example? If so, what database are you using?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,634
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #3
24 Days Ago
Use BETWEEN caluse - BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.

  1. SELECT * FROM TableName Where TestDate
  2. BETWEEN '01/01/2009' AND '01/31/2009'
Last edited by adatapost; 24 Days Ago at 9:31 pm.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,230
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 576
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #4
24 Days Ago
Here is another example of MSSQL using the between operater with parameterized SQL:
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
  4. const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)";
  5. using (SqlConnection conn = new SqlConnection(connStr))
  6. {
  7. conn.Open();
  8. using (SqlCommand cmd = new SqlCommand(query, conn))
  9. {
  10. cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180);
  11. cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today;
  12. using (SqlDataReader dr = cmd.ExecuteReader())
  13. {
  14. DataTable dt = new DataTable();
  15. dt.Load(dr);
  16. dataGridView1.DataSource = dt;
  17. }
  18. }
  19. }
  20. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC