Searching through Date

dualshock03

Well-known member
Joined
Jan 28, 2007
Messages
105
Programming Experience
1-3
Yoh geniuses... its been a long time since i posted here.. i've got a little problem behind this searching through records by means of the given minimum date to the maximum date.. i mean using a two DateTimePicker to choose the corresponding dates then search for the specfic record.

Look at my attachment image:
 

Attachments

  • searching_by_date.GIF
    searching_by_date.GIF
    22.4 KB · Views: 38
I assume you mean you want to search a database. Does the database column you want to search against contain date and time or just date? What database is it?

Also, assuming that it is a database, this question belongs in the Data Access forum, not the General forum. If so then I'll move it. Please post in the most appropriate forum in future. General is for questions that don't fit a more specific forum.
 
VB.NET:
Using connection As New SqlConnection("connection string here")
    Using command As New SqlCommand("SELECT * FROM MyTable WHERE MyColumn BETWEEN @StartDate AND @EndDate", connection)
        With command.Parameters
            .AddWithValue("@StartDate", Me.startDatePicker.Value.Date)
            .AddWithValue("@EndDate", Me.endDatePicker.Value.Date)
        End With

        'Use command here.
    End Using
End Using
That's the basic principle, which you can adapt to your specific circumstances. You create an appropriate DbCommand where the SQL code contains parameter place-holders for the date range. You then add parameters and specify the values as the Dates from the DateTimePickers. The Value property returns a Date value and the Date property of that returns the same date part with the time part zeroed to midnight.
 

Latest posts

Back
Top