Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Database and Reporting (http://www.xtremevbtalk.com/-net-database-and-reporting/)
-   -   DateTimePicker Date Range in DataGridView (http://www.xtremevbtalk.com/-net-database-and-reporting/328207-datetimepicker-date-range-datagridview.html)

SwsCheez 05-13-2016 09:30 PM

DateTimePicker Date Range in DataGridView
I am a frustrated Newb. I am trying to use a couple of datetimepickers to display the date range from an Access Database in a DataGridView. Here is the code I am using:

Dim dtp1 As String = DateTimePicker1.Text
Dim dtp2 As String = DateTimePicker2.Text
Dim strCriteria, task As String

If dtp1 = "" Then
MsgBox("Please Enter The Date Range", vbInformation, "Date Range Required")
strCriteria = "([Appt Date] >= #" & dtp1 & "# And [Appt Date] <= #" & dtp2 & "#)"
task = "SELECT * FROM BDC1 WHERE (" & strCriteria & ") order by [Appt Date]"

End If

SwsCheez 05-16-2016 08:01 PM

Wow.... Not one person has seen this?

Cerian Knight 05-17-2016 11:35 AM

The 'task' query string looks basically correct, except for possibly redundant WHERE '()'. What happens when you process the query string?

SwsCheez 05-28-2016 06:35 PM

HELP Please!!!! I just want the datagrid to show the information between the dates of datetimepicker1 and datetimepicker2. I still can't seem to get this to work. Here is my code and below it is the error that I get.

Dim dtp1 As String = DateTimePicker1.Value.ToString("#MM/dd/yyyy#")
Dim dtp2 As String = DateTimePicker2.Value.ToString("#MM/dd/yyyy#")

Dim con As OleDbConnection = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\BDC3.mdb")
Dim sql = "SELECT * FROM BDC1 WHERE [Appt Date] BETWEEN '" + dtp1 + "' AND '" + dtp2 + "' order by [Appt Date]"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(sql, con)
Dim dt As New DataTable()
DataGridView1.DataSource = dt

Here is the Error I get at "da.Fill(dt)"

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Data type mismatch in criteria expression.

PlausiblyDamp 05-29-2016 11:57 AM

If you actually look at the variable sql in a debugger and then try running your generated sql directly against the Access dtabase in question does it work?

Looking at the code you have posted however you might be adding some unneeded ' charcters around the date variables.

All times are GMT -6. The time now is 07:08 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.