473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sql query give incorrect results (date/time) issue

Hi to all.
I am pretty new to this stuff , so forgive me if I am asking the
obvious.
I am trying to extract some data from an Access database and am having
some trouble.
The SQL query that I am using (in VB.net) searches for products
depending on selected operator and a timespan.
The query works fine is my PC's system date setting is mm/dd/yyyy.
If I change it to dd/mm/yyyy the query does not return any info.

Here is the relevant code. I get the "timespan" from 2 sets of
comboboxes , that set the start and end date. ie: 21 June 2005 to 30
June 2005. The operator is also from a combobox.
-------------------------------------------------------------------
stday = Val(comStartday.SelectedItem)
stmnth = Val(comstartMnth.SelectedIndex + 1)
styr = Val(comstartyr.SelectedItem)

finday = Val(comfinday.SelectedItem)
finmnth = Val(comfinmnth.SelectedIndex + 1)
finyr = Val(comfinyr.SelectedItem)

Dim findate As DateTime = New Date(finyr, finmnth, finday, 23,
59, 59)
Dim stdate As DateTime = New Date(styr, stmnth, stday)
Dim getproducts As New OleDb.OleDbCommand("select
distinct(prod) from loginfo where oper = '" & comoperator.SelectedItem
& "' and DT >= # " & stdate & "# and DT <= #" & findate & "# ",
startup_form.mycon)
Hope you can work out what is going on there!!

The results of the query are used to populate a listbox(code not shown)

How can I make the code work on any system with any regional settings.

Thanks
Robin

Nov 21 '05 #1
4 1872
seegoon schrieb:
Hi to all.
I am pretty new to this stuff , so forgive me if I am asking the
obvious.
I am trying to extract some data from an Access database and am having
some trouble.
The SQL query that I am using (in VB.net) searches for products
depending on selected operator and a timespan.
The query works fine is my PC's system date setting is mm/dd/yyyy.
If I change it to dd/mm/yyyy the query does not return any info.

Here is the relevant code. I get the "timespan" from 2 sets of
comboboxes , that set the start and end date. ie: 21 June 2005 to 30
June 2005. The operator is also from a combobox.
-------------------------------------------------------------------
stday = Val(comStartday.SelectedItem)
stmnth = Val(comstartMnth.SelectedIndex + 1)
styr = Val(comstartyr.SelectedItem)

finday = Val(comfinday.SelectedItem)
finmnth = Val(comfinmnth.SelectedIndex + 1)
finyr = Val(comfinyr.SelectedItem)

Dim findate As DateTime = New Date(finyr, finmnth, finday, 23,
59, 59)
Dim stdate As DateTime = New Date(styr, stmnth, stday)
Dim getproducts As New OleDb.OleDbCommand("select
distinct(prod) from loginfo where oper = '" & comoperator.SelectedItem
& "' and DT >= # " & stdate & "# and DT <= #" & findate & "# ",
startup_form.mycon)
Hope you can work out what is going on there!!

The results of the query are used to populate a listbox(code not shown)

How can I make the code work on any system with any regional settings.


Use parameters instead of concatenating the string yourself. See
getproducts.Parameters (and it's documentation).

See also:
http://msdn.microsoft.com/library/en...turnvalues.asp
Armin
Nov 21 '05 #2
seegoon wrote:
How can I make the code work on any system with any regional settings.


Always specify dates in strings in ISO8601 format: yyyy-mm-dd. This is the
only non-ambiguous date format. VB.NET, VB6, MS Access and SQL Server (at
least) all understand this format.

--

(O)enone
Nov 21 '05 #3
Hi guys.
Thanks for the help. As I said I'm new to this. I read this page
mentioned above , but I may as well be reading a foreign language for
all that I understood :0(
How can I get the date into the yyyy-mm-dd format.
I tried Format(stdate , "yyyy/mm/dd') and all I get ti stdate =
yyyy/mm/dd . ie I get those letters!! Stdate had 12/07/2005 befor the
format command.
Cheers
Robin the confused

Nov 21 '05 #4
Hi again .
Finally got it working !!
I created the date in the format yyyy/mm/dd .
the next line does this: stdate = Format(tmpdate, " MM/dd/yyyy ") ,
which should swop it back again , but it seens to be working , don't
understand ,
but it works so I'm not going to touch it!!
Thanks for the tips , I'll carry on reading if anyone has any more to
offer.
Robin the slightly more confused , but less irritated

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Adam i Agnieszka Gasiorowski FNORD | last post by:
I need help width formulating the most effective (in terms of processing time) SQL query to count all the "new" documents in the repository, where "new" is defined as "from 00:00:01 up to...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
3
by: pbaugh | last post by:
Hi Folks I have a query on an Access database that has the WHERE clause : WHERE Trans.TransDate LIKE '08/04/2006*' It works fine when run in Access and returns the correct 10 rows. However, if...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
7
by: bruce.dodds | last post by:
Access seems to be handling a date string conversion inconsistently in an append query. The query converts a YYYYMM string into a date, using the following function: CDate(Right(,2) & "/1/" &...
12
by: Michel Esber | last post by:
Hello, Db2 Linux LUW FP 15. Consider table A (ID varchar, EXECUTION_DATE date). a) I want to first retrieve all IDs that have not executed during the last 90 days: select distinct ID...
15
by: Widge | last post by:
Hi, I wondered if you could help me with an issue I'm having. Currently I have a rebate calculation that is running off two tables: 1) A list of suppliers and the rebate %ages relevant to them...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.