|
-
Nov 5th, 2002, 04:08 AM
#1
Thread Starter
Member
Search a databse using date values
Hi,
I have vb form whitch contain two text boxes.
First one is Begindate
Second one is Enddate
If I want search a databse using begin date and end date how do i create sql statment.And also i want to display record in grid.
How to do that? Pl explain in simple english in details steps.
Thankx
shooter
-
Nov 5th, 2002, 04:17 AM
#2
Hi,
Use the between clause to search records between two date values.
For e.g:-
Code:
Use Northwind
go
SELECT * FROM [ORDERS] WHERE ORDERDATE BETWEEN '1996.07.06' AND '1996.07.10'
go
For populating a grid. Open a recordset with your query. And set the datasource property of the DBGrid to the recordset. That should do the trick.
Cheers!
Abhijit
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 5th, 2002, 03:02 PM
#3
Junior Member
Searching between two dates
You can make a query using a Sql string. You have to use format #Month/Day/year# in the sql String.
‘For example how to search between two dates begin an end.
Dim Sql as string
‘Me.txtBeginDate = Textbox with first Date
‘Me.txtEndDate = Textbox with end Date
Sql = “Select * from tbl... where Date(=field from tbl...) BETWEEN #" & Month(Me.txtBeginDate) & "/" & Day(Me.txtBeginDate) & "/" & year(Me.txtBeginDate) & "# And #" & Month(Me.txtEndDate) & "/" & Day(Me.txtEndDate) & "/" & year(Me.txtEndDate) & "#)”
I hope this will help You.
-
Nov 5th, 2002, 03:21 PM
#4
PowerPoster
or...
SELECT * FROM <table> where [date field] >= " & "#" & cdate(txtstartdate.text) & "#" & " and [datefield <= " & "#" and cdate(txtenddate.text) & "#"
-
Nov 7th, 2002, 12:27 PM
#5
Originally posted by Pasvorto
or...
SELECT * FROM <table> where [date field] >= " & "#" & cdate(txtstartdate.text) & "#" & " and [datefield <= " & "#" and cdate(txtenddate.text) & "#"
Pasvorto,
This appears to be a query written for access. I am using one for SQL Server.
Cheers!
Abhijit
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 7th, 2002, 12:36 PM
#6
Here's two ways we do it:
VB Code:
Dim strSQL As String
strSQL = "SELECT blah FROM tblFoo WHERE DateField BETWEEN '" & Format$(CDate(BeginDate.Text), "mm/dd/yyyy") & "' AND '" & Format$(CDate(EndDate.Text), "mm/dd/yyyy") & "'"
Set rs = objCmd.Execute strSQL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|