| | |
Fetching records based on range of dates
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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.
text Syntax (Toggle Plain Text)
SELECT * FROM TableName Where TestDate 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
0
#4 24 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 |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file filename form format forms function gdi+ gis gtk httpwebrequest image index input install internet java label list listbox listener mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remote remoting richtextbox serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer tutorial update usercontrol validation visualstudio webbrowser webcam wia windows winforms wpf xml






