Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2006, 07:09 PM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with selecting data between two dates

I would really appriciate it if someone could help me with the following. I have a Form with two DateTimePickers (dtpFrom & dtpTo) and a DataGridView. I’m trying to pass the date from (dtpFrom) and date to (dtpTo) to my query to filter my data but get the following error: “Missing Operand”. Below please find my code. Thanks.

Dim strCon As String
strCon = "Provider=VFPOLEDB.1;Data Source=D:\fm\;Collating Sequence=GENERAL"
Dim objCon As New OleDbConnection(strCon)
Dim strSelect As String
strSelect = "SELECT * FROM fuellings WHERE (td >= @FromDate) AND (td <= @ToDate)"
Dim SelectCommand As New OleDbCommand(strSelect, objCon)
Dim strFrom As String
Dim strTo As String
strFrom = dtpFrom.Text
strTo = dtpTo.Text
Try
objCon.Open()
SelectCommand.Parameters.AddWithValue("@FromDate", strFrom)
SelectCommand.Parameters.AddWithValue("@ToDate", strTo)
Dim objDA As New OleDbDataAdapter(strSelect, objCon)
Dim objDT As New Data.DataTable("fuellings")
objDA.Fill(objDT)
GridEX1.DataSource = objDT
Debug.WriteLine(objCon.State.ToString)
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message)
Finally
objCon.Close()
objCon.Dispose()
objCon = Nothing
End Try

Thanks

 
Old January 18th, 2006, 01:16 PM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check SQL BOL for the BETWEEN range check of WHERE condition.. that may help ...






Similar Threads
Thread Thread Starter Forum Replies Last Post
selecting date and previous dates harpua MySQL 0 April 5th, 2007 08:25 PM
Selecting Data from a table nkrust Javascript 7 January 11th, 2007 05:44 AM
Selecting Data from External Documents tslag XSLT 2 July 24th, 2006 10:35 AM
Chapter 6 Selecting Data in Access ,, Help Me zaidqais BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 May 5th, 2006 03:48 AM
Selecting Data.. NitinJoshi General .NET 3 January 18th, 2005 02:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.