Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




1366 posts

Uber Geek
+1 received by user: 16


Topic # 70013 16-Oct-2010 14:44
Send private message

Ok so i am making a program in visual basic express 2010, and i have it hooked upto a database made in access 2007.

I run a query on the database like "SELECT * FROM myTable WHERE myDate=#08/10/2010#"

this should work fine as i have checked my database and the dates in their afre in nz date format and their are three rows in the database with this date but my query returns nothing.

So i thought i would change my query to use american dates, so my query is now like this:

"SELECT * FROM myTable WHERE myDate=#10/08/2010#"

and for some strange reason this works even though it shouldn't.

Anyway i thought sweet i will just use american dates and it will be fine - turns out i was wrong, as soon as the date goes over the 12th day it error so when the query is like this:


"SELECT * FROM myTable WHERE myDate=#10/13/2010#"

it has an overloaded date error in visual basic.

I have no idea what i have done wrong here but any help would be fantastic as this has been frustrating me for days.

Cheers

Create new topic
Phil Gale
1107 posts

Uber Geek
+1 received by user: 44

Trusted
Red Jungle
Subscriber

  Reply # 392613 16-Oct-2010 14:46
Send private message

It's been a loooong time since I've worked with an Access DB.. but try using the format yyyy-mm-dd.




Red Jungle: we make fantastic software

RSS  Twitter  Facebook  Skype

134 posts

Master Geek
+1 received by user: 5


  Reply # 392616 16-Oct-2010 14:57
Send private message

RedJungle is correct - use the yyyy-mm-dd format. This should cover you off.

Also - it's probably a good idea to make sure the machine running IIS (either your development machine or your server) is setup to use NZ regional settings - as this can cause confusion if not set properly.

So - when you're inserting, or selecting - use the above format and you should be aok. 

 
 
 
 




1366 posts

Uber Geek
+1 received by user: 16


  Reply # 392648 16-Oct-2010 17:40
Send private message

OK cheers thanks very much guys i will give that ago when i got home.

Before i started this project i did check the regional settings and they were set to american for some strange reason.

Thanks again :)

Phil Gale
1107 posts

Uber Geek
+1 received by user: 44

Trusted
Red Jungle
Subscriber

  Reply # 392652 16-Oct-2010 17:50
Send private message

The other (better) option would be to move towards parameterised queries. So rather than passing in a formatted date string for your query, you would be able to use an actual DateTime object. Much easier, and much safer from a SQL Injection point of view.




Red Jungle: we make fantastic software

RSS  Twitter  Facebook  Skype

Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.


Geekzone Live »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.