Home All Groups Group Topic Archive Search About

Cast from string "" to type 'Date' is not valid

Author
3 Feb 2006 9:42 AM
zafzal@gmail.com
Hello all,


    I have a textbox in my asp.net (vb.net) aplicattion, I need to
assign it's value to a Variable of type DATE, but it's not a required
field, so sometimes I want to send a blank field.

    I declared a variable as a date datatype and when it´s going to
receive
the content of the text field, it shows the following error "Cast from
string "" to
type 'Date' is not valid"

What should I do to handle this problem.

Author
3 Feb 2006 9:55 AM
Cor Ligthert [MVP]
ZafZal,

It depends if the receiving field is a db field, than it has to be
DbNull.value
if the receiving field is a net datatime, than you can use = nothing (which
makes from it  something as 1-1-1 1:1:1)

I hope this helps,

Cor
Author
8 Feb 2006 7:17 PM
Jim Wooley
If you are using 2.0, you can look into the Nullable Date type
    Dim MyDate as Nullable(Of Date)

Using objects, I often expose the date property as a string and handle the
validity of the date as a business rule.

Jim Wooley

<zaf***@gmail.com> wrote in message
news:1138959745.470834.49000@g49g2000cwa.googlegroups.com...
Hello all,


    I have a textbox in my asp.net (vb.net) aplicattion, I need to
assign it's value to a Variable of type DATE, but it's not a required
field, so sometimes I want to send a blank field.

    I declared a variable as a date datatype and when it´s going to
receive
the content of the text field, it shows the following error "Cast from
string "" to
type 'Date' is not valid"

What should I do to handle this problem.