John Nuñez
John Nuñez

Reputation: 1830

Select a date range to filter a DGV using RowFilter

I am taking the dates through datepicker controls, but not achieving any success, anyone have any suggestions.

I tryed:

Dim fromDate As New DateTime(startdate_picker_search_supplierinvoice.Text)
Dim toDate As New DateTime(enddate_picker_search_supplierinvoice.Text)

query &= "supplier_invoice_date >= '" & fromDate & "' AND supplier_invoice_date <= '" & toDate & "'"
invoicesresults_datagrid_search_supplierinvoice.DataSource = SelectDataTable(dt, query)

Error: Conversion from string "Tuesday, July 17, 2012" to type 'Long' is not valid.

Upvotes: 1

Views: 204

Answers (2)

Holger Brandt
Holger Brandt

Reputation: 4354

Don't use the .Text property which is returning the full written out date. Instead use:

Dim fromDate As DateTime = startdate_picker_search_supplierinvoice.Value
Dim toDate As DateTime = enddate_picker_search_supplierinvoice.Value

and then the `.ToString' extension.

query &= "supplier_invoice_date >= '" & fromDate.ToShortDateString & "' AND supplier_invoice_date <= '" & toDate.ToShortDateString & "'"
invoicesresults_datagrid_search_supplierinvoice.DataSource = SelectDataTable(dt, query)

Upvotes: 2

Chris Stauffer
Chris Stauffer

Reputation: 352

The problem is that you are declaring a DateTime object, and the constructor you are using is expecting (ticks as Long). You should be using

Dim toDate As DateTime
toDate = enddate_picker_search_supplierinvoice.Value

Note that .Value returns the date, rather than a String.

Upvotes: 1

Related Questions