| | |
Fetching records based on range of dates
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
0
#3 16 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; 16 Days Ago at 9:31 pm.
Failure is not fatal, but failure to change might be. - John Wooden
0
#4 16 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 algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml






