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

Z

zafzal

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

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
 
J

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

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.
 

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