i want to call items in a database based on a date range...can someone help me with this..i really don't have any idea how

It depends on what database engine you are using. For example, in Access you would do (depending on your system's short-date format)

 WHERE thedate >= #2012-03-07# AND thedate <= #2012-09-15#

but in MS SQL you could do

 WHERE thedate BETWEEN '2012-03-07' AND '2012-09-15'

assuming "thedate" is the name of one of the table columns.

what if the date range are chosen from datetimepicker1 and datetimepicker2?

yes you can do same by using datetime picker .try something like this,

'here is a code to show the data in grid 

dim con as new sqlconnection("your connection string")
dim strQuery as string 
strQuery = "select * from table1 where 1=1 "
'here is a code to add from date and to date , sometime if from date is selected and To date is not 
'not defined then this code will show all records having InvoiceDate equal to or greater then selected date
'same like to date.
if dateTimePickerFrom.text <> "" then 
    strQuery = " and InvoiceDate >= '" + dateTimePickerFrom.text + "'"
end if
if dateTimePickerTo.text <> "" then 
    strQuery = " and InvoiceDate <= '" + dateTimePickerTo.text + "'"
end if
dim da as new sqldataadapter(strQuery,con)
dim dt as new datatable
datagrid.datasource = dt

i typed this code here so may be there are some spelling mistakes :P

Best Regards

This article has been dead for over six months. Start a new discussion instead.