What may be wrong here?

S

Scirious

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.
 
S

Stephan Rose

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
 
S

Stephan Rose

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
 
S

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.

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?
 
T

Tom Dacon

Surely you can't mean aaaa in that format string? The aaaa just gets stuffed
into the output string, giving you something like "15/06/aaaa", and
DateTime.Parse barfs on it as you might expect. Now if you used yyyy, you'd
have something that DateTime.Parse could work with.

Tom Dacon
Dacon Software Consulting
 
S

Stephan Rose

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
 
S

Scirious

Sorry for the aaaa thing. I was thinking in portugese, but yea, it is the
year format.

Scirious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top