| | |
Fetching records based on range of dates
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
0
#3 Nov 9th, 2009
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.
text Syntax (Toggle Plain Text)
SELECT * FROM TableName Where TestDate BETWEEN '01/01/2009' AND '01/31/2009'
Last edited by adatapost; Nov 9th, 2009 at 9:31 pm.
0
#4 34 Days Ago
Here is another example of MSSQL using the between operater with parameterized SQL:
C# Syntax (Toggle Plain Text)
private void button2_Click(object sender, EventArgs e) { const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)"; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180); cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today; using (SqlDataReader dr = cmd.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; } } } }
![]() |
Similar Threads
- n XSLT variables to fetch n records from xml file (XML, XSLT and XPATH)
- date query problem (Visual Basic 4 / 5 / 6)
- Select only the most recent date from records (MS SQL)
- searching with date value (VB.NET)
- seeming limit on number of shelve records? (Python)
- Having trouble with range dates (MySQL)
- Here is the doc file for the assignment (C++)
- Population a dataset row by row based on criteria (VB.NET)
- Retrieving dates from a dataset (Month Calendar) (VB.NET)
Other Threads in the C# Forum
- Previous Thread: Web content blocking
- Next Thread: socket exception
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






