DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
Go Back  Xtreme Visual Basic Talk > > > DateTimePicker Date Range in DataGridView


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2016, 10:30 PM
SwsCheez SwsCheez is offline
Newcomer
 
Join Date: Oct 2012
Posts: 13
Question 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

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

End If
__________________
I'll procrastinate tomorrow
Reply With Quote
  #2  
Old 05-16-2016, 09:01 PM
SwsCheez SwsCheez is offline
Newcomer
 
Join Date: Oct 2012
Posts: 13
Default

Wow.... Not one person has seen this?
__________________
I'll procrastinate tomorrow
Reply With Quote
  #3  
Old 05-17-2016, 12:35 PM
Cerian Knight's Avatar
Cerian KnightDateTimePicker Date Range in DataGridView Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,193
Default

The 'task' query string looks basically correct, except for possibly redundant WHERE '()'. What happens when you process the query string?
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #4  
Old 05-28-2016, 07:35 PM
SwsCheez SwsCheez is offline
Newcomer
 
Join Date: Oct 2012
Posts: 13
Default

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()
da.Fill(dt)
con.Close()
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.
__________________
I'll procrastinate tomorrow
Reply With Quote
  #5  
Old 05-29-2016, 12:57 PM
PlausiblyDamp's Avatar
PlausiblyDampDateTimePicker Date Range in DataGridView PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

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.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply

Tags
range, date, dim, dtp1, string, strcriteria, date], datagridview, [appt, datetimepicker2.text, dtp2, task, vbinformation, required, datetimepicker1.text, enter, msgboxplease, me.refresh, couple, datetimepickers, frustrated, newb, display, datetimepicker, code


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
 
DateTimePicker Date Range in DataGridView
DateTimePicker Date Range in DataGridView
 
-->