Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 August 7th, 2008, 03:10 PM
Registered User
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.Net - Access DB - Date compare

I am having a heck of a time trying to figure out what is wrong with this code. Trying to compare a system date with a date in an Access DB using a user defined date.

Initially, I had the compare in the Select Statement and then moved it into a Do While loop as a further test.

The results I am getting is as though the compare is only seeing the Month and Day and not the year. I am able to get the return of anything after today until 12/31/08.

Thanks for your help.
johnc

Anyone see anything wrong with these statements?

SQL statement version:

Code:
Command.CommandText = "SELECT PageIndex FROM CustomerPicks_Reviews WHERE (ItemNumber = '" & intItemNum & "') AND (ExpirationDate >= '" & Format(System.DateTime.Now, "MM-dd-yy") & "')"
Loop version:

Code:
            DataReaderIndex = CommandIndex.ExecuteReader()
            Do While (DataReaderIndex.Read())
                strExpirationDateDB = DataReaderIndex.GetValue(1).ToString
                MsgBox(strExpirationDateDB)
                If DataReaderIndex.GetValue(1).ToString >= Format(System.DateTime.Now, "MM-dd-yy").ToString Then
                    CmbBxSglOthIpsPage.Items.Add(DataReaderIndex.GetValue(0))
                End If
            Loop


 
Old August 7th, 2008, 03:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there.. you have to format the table field to the same format as the other date...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 7th, 2008, 04:11 PM
Registered User
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for a quick response.

This Database change would be needed even when converting the system date to match the retrieved DB date string?

It is a little confusing.

 
Old August 7th, 2008, 04:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

yes.. because the db format could be diferent from the system date..

Anyway, after revisit your code, You are selecting pageindex only and you are comparing it with a date?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 7th, 2008, 04:23 PM
Registered User
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will change the DB to a date format and give it a try.

On the Loop version, I did pull the ExpirationDate along with the PageIndex. I didn't include the Select statement with the loop code.

Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect to Access db thru VB.NET? am_kuthus Visual Studio 2008 1 June 3rd, 2008 04:48 AM
Connecting to Access 20007 DB with vb.net JohnBoy VB.NET 1 May 21st, 2008 01:26 PM
New in .Net VB but learning datareader, access DB tjgrindsted ASP.NET 2.0 Basics 2 February 6th, 2007 08:49 PM
Compare Two MS access db file and find missing rec lawsoncobol Reporting Services 0 August 3rd, 2006 04:14 AM
Quickest way to write data to Access DB in VB.NET aslyon ADO.NET 4 September 22nd, 2004 08:00 AM





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