473,662 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Date Problem

Given that variable dt = "3/31/2007", why does it produce the following
exception on some machines? It works fine on my PC, but others have sent me
this exception information because it threw up on their PC.

DLDT.Columns("D ate").DataType = GetType(Date)
dr.Item("Date") = Date.Parse(dt.T rim).ToShortDat eString

System.Argument Exception: The string was not recognized as a valid DateTime.
Couldn't store <3/31/2007in Date Column. Expected type is DateTime. --->
System.FormatEx ception: The string was not recognized as a valid DateTime.

Apr 30 '07 #1
17 2266
Terry Olsen wrote:
Given that variable dt = "3/31/2007", why does it produce the following
exception on some machines? It works fine on my PC, but others have sent me
this exception information because it threw up on their PC.

DLDT.Columns("D ate").DataType = GetType(Date)
dr.Item("Date") = Date.Parse(dt.T rim).ToShortDat eString

System.Argument Exception: The string was not recognized as a valid DateTime.
Couldn't store <3/31/2007in Date Column. Expected type is DateTime. --->
System.FormatEx ception: The string was not recognized as a valid DateTime.
The date format was not recognised by the database. This is common when
using this type of date format without specifying a culture when
converting it.

Specify a Culture (or FormatInfo) when parsing the string, and don't
convert it back to a string before putting it in the table.

--
Göran Andersson
_____
http://www.guffa.com
Apr 30 '07 #2
Terry,

Did you ever tried the method CDate from the extendened Net Library
Microsoft Visual Basic.
Almost all conversion functions have no relation anymore with VB6 but are
optimized Net ones.

Cor

"Terry Olsen" <to******@hotma il.comschreef in bericht
news:OT******** ******@TK2MSFTN GP02.phx.gbl...
Given that variable dt = "3/31/2007", why does it produce the following
exception on some machines? It works fine on my PC, but others have sent
me this exception information because it threw up on their PC.

DLDT.Columns("D ate").DataType = GetType(Date)
dr.Item("Date") = Date.Parse(dt.T rim).ToShortDat eString

System.Argument Exception: The string was not recognized as a valid
DateTime.
Couldn't store <3/31/2007in Date Column. Expected type is
DateTime. --->
System.FormatEx ception: The string was not recognized as a valid DateTime.

Apr 30 '07 #3
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb:
Did you ever tried the method CDate from the extendened Net Library
Microsoft Visual Basic.
'CDate' is a language feature, not a library feature.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Apr 30 '07 #4
>Given that variable dt = "3/31/2007", why does it produce the following
>exception on some machines? It works fine on my PC, but others have sent
me this exception information because it threw up on their PC.

DLDT.Columns(" Date").DataType = GetType(Date)
dr.Item("Date" ) = Date.Parse(dt.T rim).ToShortDat eString

System.Argumen tException: The string was not recognized as a valid
DateTime.
Couldn't store <3/31/2007in Date Column. Expected type is
DateTime. --->
System.FormatE xception: The string was not recognized as a valid
DateTime.

The date format was not recognised by the database. This is common when
using this type of date format without specifying a culture when
converting it.

Specify a Culture (or FormatInfo) when parsing the string, and don't
convert it back to a string before putting it in the table.
Will this work?

dr.Item("Date") =Date.Parse(dt. Trim,System.Glo balization.Cult ureInfo.Current Culture.DateTim eFormat)

May 1 '07 #5
Along the same lines, I have this code:

DLDT.Columns("F ileSize").DataT ype = GetType(Double)
dr.Item("FileSi ze") = CType(stringVar ,Double)

And while checking to see if my Date change worked by changing the language
settings, the FileSize column went blank. So I guess I need to figure out
how to make the FileSize column global...
May 1 '07 #6
Herfried,

Are you sure than I cannot use it in C# in my idea?

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:uY******** ******@TK2MSFTN GP03.phx.gbl...
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb:
>Did you ever tried the method CDate from the extendened Net Library
Microsoft Visual Basic.

'CDate' is a language feature, not a library feature.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 1 '07 #7
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb:
Are you sure than I cannot use it in C# in my idea?
Yes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
May 1 '07 #8
Terry Olsen wrote:
>>Given that variable dt = "3/31/2007", why does it produce the following
exception on some machines? It works fine on my PC, but others have sent
me this exception information because it threw up on their PC.

DLDT.Columns( "Date").DataTyp e = GetType(Date)
dr.Item("Date ") = Date.Parse(dt.T rim).ToShortDat eString

System.Argume ntException: The string was not recognized as a valid
DateTime.
Couldn't store <3/31/2007in Date Column. Expected type is
DateTime. --->
System.Format Exception: The string was not recognized as a valid
DateTime.
The date format was not recognised by the database. This is common when
using this type of date format without specifying a culture when
converting it.

Specify a Culture (or FormatInfo) when parsing the string, and don't
convert it back to a string before putting it in the table.

Will this work?

dr.Item("Date") =Date.Parse(dt. Trim,System.Glo balization.Cult ureInfo.Current Culture.DateTim eFormat)

Using CurrentCulture will give you the same effect as not specifying any
culture at all, as that is what's used by default. CurrentCulture
contains the culture selected by the user, and it will differ on
different computers. Create a CultureInfo object for the culture that
you want to use for the conversion.

--
Göran Andersson
_____
http://www.guffa.com
May 1 '07 #9
Terry Olsen wrote:
Along the same lines, I have this code:

DLDT.Columns("F ileSize").DataT ype = GetType(Double)
dr.Item("FileSi ze") = CType(stringVar ,Double)

And while checking to see if my Date change worked by changing the language
settings, the FileSize column went blank. So I guess I need to figure out
how to make the FileSize column global...
The decimal separator or a floating point number is also culture
dependand. Use the Double.Parse method to parse the string, so that you
can specify the culture to use for the conversion.

--
Göran Andersson
_____
http://www.guffa.com
May 1 '07 #10

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

Similar topics

3
2849
by: Jim Irvine | last post by:
I have a small database made up of 2 tables. I have a report that is driven from a query. On the report are a couple of fields linked to memo boxes in the table. Everytime I run the report I get the following strange characters instead of data. �_ Ἃ These actually show us as square boxes and capital A's with a tilde etc.
3
1686
by: Jim in Arizona | last post by:
I'm going insane! I don't know if it's just that the .net 2.0 framework is buggy or if it really is my code. This is pretty hard to explain since I can't even begin to nail down why this is happening. I have two text boxes. One is for the ID number, which when postback occurs, inserts into the related table as the foreign key. The other text box is for notes that go along side the foreign key of the the related table. Basically, the...
10
2497
by: Trapulo | last post by:
Why Now.Date.Subtract(New Date(2000, 1, 1)).Days returns 731529?? It is a too big value a think! I aspect something as 1030-1100....
1
1180
by: Maileen | last post by:
Hi, I finished my application butonce again i have some strange behavior with XML/text functions... for example, here below is a function which worked perfectly till now and now generate an error : "An unhandled exception of type 'System.NullReferenceException' occured in Unknown Module. Addition information : object reference not set to an instance of object"
2
1817
by: Paul Furman | last post by:
I don't know, maybe this isn't strange but someone else set up the shopping card coding I'm working with, the way it works is to get the time() in seconds like 1172693735 and that's the shopper_ID number and the shopping_cart_last_modified number is generated the same way once they check out... then an invoice number is generated by subtracting the two numbers (shopper_ID is older from when they registered). Is this strange or bad or...
1
6985
by: Victor | last post by:
Hi guys, I have a very strange problem with scriptmanager here. I want to load a js (which is embed in the project) but everytime i try to load that, it gives me error like Specified argument was out of the range of valid values. Parameter name: utcDate Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in...
3
3050
by: Reg143 | last post by:
Hi all, The code below loops from a starting date, incrementing the date and displaying date and day-of-week. Everything is fine until 2007-11-04 is reached. Any help would be appreciated. Thanks in advance. ---------------------------------------------------- Dates.php
1
1543
by: Dan2kx | last post by:
Hello (again) i have a rather strange problem to tackle i am still doing the holiday database (for those who have helped me before) and now need (which means i have to rethink everything) to assign to each staff member a two week shift pattern what i have come up with so far is a table with this info LineID - autonumber StaffID - foreign key CurrentID - this relates to the most current shiift pattern (cos i cant delete info (audits))
3
1421
by: Tomasz J | last post by:
Hello Developers, I have a control derived from System.Web.UI.WebControls.WebControl. Control has this property: public string Value { set { _value = value; } get { return _value; }
2
2629
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8546
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4180
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.