Home > Archive > C# > June 2006 > What may be wrong here?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
What may be wrong here?
|
|
| Scirious 2006-06-17, 7:02 pm |
| People, I'm working in a project in Asp.Net 1.1 where I need to record
some info in an Oracle database. To do such, there is an object that
stores some this info, including a date in a string variable.
Something that is gotten this way.
DateTime dt = new DateTime.Today;
string date = dt.ToString("dd/MM/aaaa");
After getting the date this way it goes through many objects in it's way
to be recordend, but then I get the following error stack:
--------------------
(String was not recognized as a valid DateTime.) at
System.DateTimeParse.GetDayOfNNY(DateTimeResult result,
DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at
System.DateTimeParse.ProcessTerminaltState(Int32 dps,
DateTimeResult result, DateTimeRawInfo raw,
DateTimeFormatInfo dtfi) at
System.DateTimeParse.Parse(String s, DateTimeFormatInfo
dtfi, DateTimeStyles styles) at System.DateTime.Parse(String
s, IFormatProvider provider, DateTimeStyles styles) at
System.DateTime.Parse(String s, IFormatProvider provider) at
System.DateTime.Parse(String s) at
codeplan.BusinessRules.BusProposta.inserir(Proposta prop) at
codeplan.Web.PrstIncluir.OnSubmit(Char command)
--------------------
Any one have any ideas of what can be causing this? I can't post the
whole code here because it is a commercial product but even generic
answers would be appreciated.
TIA,
Scirious.
| |
| Stephan Rose 2006-06-17, 7:02 pm |
| On Thu, 15 Jun 2006 18:28:36 -0500, Scirious <scirious@scirious.com>
wrote:
>People, I'm working in a project in Asp.Net 1.1 where I need to record
>some info in an Oracle database. To do such, there is an object that
>stores some this info, including a date in a string variable.
>
>Something that is gotten this way.
>
>DateTime dt = new DateTime.Today;
>string date = dt.ToString("dd/MM/aaaa");
>
>After getting the date this way it goes through many objects in it's way
>to be recordend, but then I get the following error stack:
>
>--------------------
>(String was not recognized as a valid DateTime.) at
>System.DateTimeParse.GetDayOfNNY(DateTimeResult result,
>DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at
>System.DateTimeParse.ProcessTerminaltState(Int32 dps,
>DateTimeResult result, DateTimeRawInfo raw,
>DateTimeFormatInfo dtfi) at
>System.DateTimeParse.Parse(String s, DateTimeFormatInfo
>dtfi, DateTimeStyles styles) at System.DateTime.Parse(String
>s, IFormatProvider provider, DateTimeStyles styles) at
>System.DateTime.Parse(String s, IFormatProvider provider) at
>System.DateTime.Parse(String s) at
>codeplan.BusinessRules.BusProposta.inserir(Proposta prop) at
>codeplan.Web.PrstIncluir.OnSubmit(Char command)
>--------------------
>
>Any one have any ideas of what can be causing this? I can't post the
>whole code here because it is a commercial product but even generic
>answers would be appreciated.
>
>TIA,
>Scirious.
Yea big question, why are you passing the date around as a string? Why
not pass the date time object itself or at the very least the tick
count.
Just because you produced the output with DateTime.ToString() does not
mean DateTime.Parse can parse it again as the formatting is entirely
up to you and can easily mismatch what Parse expects.
--
Stephan
2003 Yamaha R6
kimi no koto omoidasu hi
nante nai no wa
kimi no koto wasureta toki ga nai kara
| |
| Stephan Rose 2006-06-17, 7:02 pm |
|
>
>Yea big question, why are you passing the date around as a string? Why
>not pass the date time object itself or at the very least the tick
>count.
>
>Just because you produced the output with DateTime.ToString() does not
>mean DateTime.Parse can parse it again as the formatting is entirely
>up to you and can easily mismatch what Parse expects.
Also even if Parse() succeeds on the output from ToString() you cannot
gurantee that the result is the same DateTime that you intially
converted to a string.
Reason is this...just to give one example of the many ways that can
get screwed up.
If you lets say take April 10th, in Month/Day format this is 04/10 but
in Day/Month format this is 10/04
There is absolutely no way for Parse to know if day or month comes
first.
--
Stephan
2003 Yamaha R6
kimi no koto omoidasu hi
nante nai no wa
kimi no koto wasureta toki ga nai kara
| |
| Scirious 2006-06-17, 7:02 pm |
| > Yea big question, why are you passing the date around as a string? Why
> not pass the date time object itself or at the very least the tick
> count.
Because this date is actually generated before the page submited, at the
page load. And it is stored in a label and then this date is gotten from
this lable. I may try creating a new DateTime object since it is expected
to be sent tha same day. =P But the Oracle DB will be expecting a date in
the dd/MM/aaaa formatç. Can it be created in this format?
| |
| Stephan Rose 2006-06-17, 7:02 pm |
| On Thu, 15 Jun 2006 18:49:33 -0500, Scirious <scirious@scirious.com>
wrote:
>
>Because this date is actually generated before the page submited, at the
>page load. And it is stored in a label and then this date is gotten from
>this lable. I may try creating a new DateTime object since it is expected
>to be sent tha same day. =P But the Oracle DB will be expecting a date in
>the dd/MM/aaaa formatç. Can it be created in this format?
I am not sure what aaaa is, I assume it is some type of year-format, I
usually use yyyy. I am not even sure if aaaa is something that is
supported.
But regardless, you can format a string representation of your
date/time any way you want either by using ToString or accessing the
Month, Day, Year, etc. properties directly and converting those to
strings to piece things together if ToString won't do the job for you
the way you want it.
That really, is all up to you. So sure, you can pass that information
to your database and display it to your user in any way you wish.
You just can't expect Parse to know what to do with the custom
formatting you are using.
--
Stephan
2003 Yamaha R6
kimi no koto omoidasu hi
nante nai no wa
kimi no koto wasureta toki ga nai kara
| |
| Scirious 2006-06-17, 7:02 pm |
| Sorry for the aaaa thing. I was thinking in portugese, but yea, it is the
year format.
Scirious.
|
|
|
|
|