Hi folks
I have an C# app. connecting to a MS-ACCESS database with several tables.
In a specific situations I have problems with a DateTime type in a table.
The problem
is when I want to select records from a table in a specific period the day
and month
seems to be swapped in the query, but it only happens when the swapping
gives a
valid date eg.
12/10/2005 (12. Oct. 2005) returns records on 10/12/2005 (10. Dec. 2005)
23/05/2005 (23. May 2005) returns records correctly since 05/23/2005 is not
a valid date with danish regional settings.
The query is:
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE [BeginDate] >= #" +
_start + "# " AND [BeginDate] <= #" + _end + "#"
_start and _end are of type DateTime
My PC in running with danish regional settings and if I shift to en-US
settings in the control panel, this
fixes the problem, but that is not a solution for me.
Any suggestions to solve this problem
Thanks in advance.
Kim W. 4 1182
Hey Kim,
First, the access news groups may be of more assistance than here;
JetSQL in Access is different than TransactSQL in SQL Server, and they
may have some more insight into this.
Obviously, you're running into transation issues because of the
formatting of dates; in the US, 23/05/2005 is not a valid date (since
our date standards default to mm/dd/yyyy). That would explain why
#12/10/2005# would return records in December, because that's the US
standard. As to how to fix it, I don't know.
The first step I would take, however, is to be sure the SQL statement
being passed to your database system is what you think it is. Have you
printed out the SQL statement and pasted it into a query in Access to
see if it gives you the results you want? Are your sure the C#
application is not reformatting your dates?
You could also try tricking the system by forcing the dates on both
sides of the equality to be formatted the same; it's been a long time
since I've worked in access, but I believe there's a FORMAT command
that would do it.
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE
FORMAT([BeginDate] ,'dd/mm/yyyy')>= FORMAT(#" +
_start + "#,'dd/mm/yyyy') " AND FORMAT([BeginDate],'dd/mm/yyyy') <=
FORMAT(#" + _end + "#,'dd/mm/yyyy')"
Again, the Access gurus in another forum might have better suggestions,
but this is all I could think of.
HTH,
Stu
Hey Kim,
First, the access news groups may be of more assistance than here;
JetSQL in Access is different than TransactSQL in SQL Server, and they
may have some more insight into this.
Obviously, you're running into transation issues because of the
formatting of dates; in the US, 23/05/2005 is not a valid date (since
our date standards default to mm/dd/yyyy). That would explain why
#12/10/2005# would return records in December, because that's the US
standard. As to how to fix it, I don't know.
The first step I would take, however, is to be sure the SQL statement
being passed to your database system is what you think it is. Have you
printed out the SQL statement and pasted it into a query in Access to
see if it gives you the results you want? Are your sure the C#
application is not reformatting your dates?
You could also try tricking the system by forcing the dates on both
sides of the equality to be formatted the same; it's been a long time
since I've worked in access, but I believe there's a FORMAT command
that would do it.
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE
FORMAT([BeginDate] ,'dd/mm/yyyy')>= FORMAT(#" +
_start + "#,'dd/mm/yyyy') " AND FORMAT([BeginDate],'dd/mm/yyyy') <=
FORMAT(#" + _end + "#,'dd/mm/yyyy')"
Again, the Access gurus in another forum might have better suggestions,
but this is all I could think of.
HTH,
Stu
Hi
Thanks for the advices, it really saved my day. Using a little
string manipulation and explicity tell the MS-Access the DateTime
format using the FORMAT in the sql string solved the problem.
Best regards
Kim W.
"Stu" <st**************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... Hey Kim,
First, the access news groups may be of more assistance than here; JetSQL in Access is different than TransactSQL in SQL Server, and they may have some more insight into this.
Obviously, you're running into transation issues because of the formatting of dates; in the US, 23/05/2005 is not a valid date (since our date standards default to mm/dd/yyyy). That would explain why #12/10/2005# would return records in December, because that's the US standard. As to how to fix it, I don't know.
The first step I would take, however, is to be sure the SQL statement being passed to your database system is what you think it is. Have you printed out the SQL statement and pasted it into a query in Access to see if it gives you the results you want? Are your sure the C# application is not reformatting your dates?
You could also try tricking the system by forcing the dates on both sides of the equality to be formatted the same; it's been a long time since I've worked in access, but I believe there's a FORMAT command that would do it.
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE FORMAT([BeginDate] ,'dd/mm/yyyy')>= FORMAT(#" + _start + "#,'dd/mm/yyyy') " AND FORMAT([BeginDate],'dd/mm/yyyy') <= FORMAT(#" + _end + "#,'dd/mm/yyyy')"
Again, the Access gurus in another forum might have better suggestions, but this is all I could think of.
HTH, Stu
Hi
Thanks for the advices, it really saved my day. Using a little
string manipulation and explicity tell the MS-Access the DateTime
format using the FORMAT in the sql string solved the problem.
Best regards
Kim W.
"Stu" <st**************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... Hey Kim,
First, the access news groups may be of more assistance than here; JetSQL in Access is different than TransactSQL in SQL Server, and they may have some more insight into this.
Obviously, you're running into transation issues because of the formatting of dates; in the US, 23/05/2005 is not a valid date (since our date standards default to mm/dd/yyyy). That would explain why #12/10/2005# would return records in December, because that's the US standard. As to how to fix it, I don't know.
The first step I would take, however, is to be sure the SQL statement being passed to your database system is what you think it is. Have you printed out the SQL statement and pasted it into a query in Access to see if it gives you the results you want? Are your sure the C# application is not reformatting your dates?
You could also try tricking the system by forcing the dates on both sides of the equality to be formatted the same; it's been a long time since I've worked in access, but I believe there's a FORMAT command that would do it.
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE FORMAT([BeginDate] ,'dd/mm/yyyy')>= FORMAT(#" + _start + "#,'dd/mm/yyyy') " AND FORMAT([BeginDate],'dd/mm/yyyy') <= FORMAT(#" + _end + "#,'dd/mm/yyyy')"
Again, the Access gurus in another forum might have better suggestions, but this is all I could think of.
HTH, Stu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcus |
last post by:
Hello,
I recently converted all my existing MyISAM tables to InnoDB tables
through phpmyadmin. I noticed some strange behavior whenever I would
refresh the screen, as phpmyadmin would report...
|
by: Dmitriy Iassenev |
last post by:
hi,
I found an interesting thing in operator behaviour in C++ :
int i=1;
printf("%d",i++ + i++);
I think the value of the expression "i++ + i++" _must_ be 3, but all the
compilers I tested...
|
by: thulsey |
last post by:
Hi all,
I've got some strange behavior happening in Firefox and Safari (Khtml
and Gecko) that displays *almost* fine in IE6.0 (still trying to get
pixels to line up, anal anal anal...)
To...
|
by: Alexander Inochkin |
last post by:
Hi!
I found same strange behavior of ASP.NET. It is possible this is the bug.
Follow the steps:
|
by: ivb |
last post by:
Hi all,
I am using DB2 8.1.11.1 on NT with ASP.NET 1.1
When application make connection to database (via ADO.NET), it set
"Connection timeout" parameter to 30 seconds.
After, when my webpage...
| |
by: Joseph Geretz |
last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm
adding matching pairs of Toolbar buttons and Menu items. All of the buttons
and menu items are wired up to send events to...
|
by: sara |
last post by:
Very strange behavior, but I suspect some is A2K and some might be for
me to correct. Just trying to see if anyone can help and advise.
We have a database that's been running for a few years...
|
by: Nicholas Palmer |
last post by:
Hi all,
Got a question about the AspCompat=true page property. First a little
background. We have an ASP.NET app that uses two COM components. The first
is the Microsoft OWC 11 components and...
|
by: david |
last post by:
I took old code and decided to modify it a bit, and I just noticed
that it does not compile at all and before server one of severs (main)
crashed in the system it was working fine (I am really sure...
|
by: Pilcrow |
last post by:
This behavior seems very strange to me, but I imagine that someone will
be able to 'explain' it in terms of the famous C standard.
-------------------- code -----------------------------------...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |