Allow Null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a bunch of textboxes that it is all right for them to be null

How do I program that? I keep getting an error that says Null is no longer supported

Sandy
 
Sandy said:
I have a bunch of textboxes that it is all right for them to be
null.

How do I program that? I keep getting an error that says Null is no
longer supported.

You're talking about the Null value in databases? It's represented by
DBNull.Value. You can not set DBNull into a textbox. A textbox only contains
a string (length 0 to
much-more-than-you-can-read-and-write-and-fits-in-your-memory-without-swappi
ng-five-days-long). What did I wanna say?... Ah, ok: You /could/ use a
special string, like "(Null)" to represent a Null value in a textbox, but
only if this special string will never be a normal field content in the
database. Even if, it's not very user friendly because the user would have
to type this string to store a Null value. I'd probably use a checkbox
(without text) in front of the textbox. If checked, the textbox' content is
stored in the DB, otherwise Null is stored.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi Armin

I guess I wasn't too clear. These textboxes are not connected to any database. They are textboxes that can contain a DateTime value or can contain nothing. I need code that essentially says "If the textbox is empty, disregard the code that pertains to that textbox."

The error generated is: "System.InvalidCastException. Cast from string "" to type 'Date' is not valid.

If I could find away to have the textboxes default to a 00:00:00 time value if they were blank, that would work, but I don't know how to do that

As long as all the textboxes are filled in with a time, the code works. If some are left blank, I get the error

Any ideas

Sandy
 
Hi Sandy,

You mean
\\\
dim mydate as date
if isdate(textbox1.text) then
mydate=cdate(textbox1.text)
end if
///
I hope this helps?

Cor
 
Sandy said:
Hi Armin:

I guess I wasn't too clear.

Right. ;-) "Null" has no relation to strings and dates and textboxes.
These textboxes are not connected to any
database. They are textboxes that can contain a DateTime value or
can contain nothing. I need code that essentially says "If the
textbox is empty, disregard the code that pertains to that textbox."

The error generated is: "System.InvalidCastException. Cast from
string "" to type 'Date' is not valid."

If I could find away to have the textboxes default to a 00:00:00 time
value if they were blank, that would work, but I don't know how to do
that.

A date time value never contains only a time. It always contains a date and
a time. You could use DateTime.Minvalue, which is the 1st January 0001
00:00, as a special date and time to represent what you need.
As long as all the textboxes are filled in with a time, the code
works. If some are left blank, I get the error.

What about "If"?

dim d as date

If text1.text.length = 0 then
d = datetime.minvalue
else
'do the conversion
end if

As there might still be errors in the else block, I'd use a try/catch block
within the else block.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "=?Utf-8?B?U2FuZHk=?= said:
I have a bunch of textboxes that it is all right for them to be null.

How do I program that? I keep getting an error that says Null is no longer supported.

Post the code you already have...
 
Hi Sandy,

In VBA it would be as follows:

If IsNull(rs.Fields("FieldName").Value) Then
txtFields(0).Text = ""
Else
txtFields(0).Text = rs.Fields("FieldName").Value
End if

That code is what works when using DAO, and it will be
very very similar for ADO objects as well.

Hope that helps.

--
Jim Carlock
http://www.microcosmotalk.com/
Post replies to the newsgroup.


Hi Armin:

I guess I wasn't too clear. These textboxes are not connected to any
database. They are textboxes that can contain a DateTime value or can
contain nothing. I need code that essentially says "If the textbox is
empty, disregard the code that pertains to that textbox."

The error generated is: "System.InvalidCastException. Cast from string ""
to type 'Date' is not valid."

If I could find away to have the textboxes default to a 00:00:00 time value
if they were blank, that would work, but I don't know how to do that.

As long as all the textboxes are filled in with a time, the code works. If
some are left blank, I get the error.

Any ideas?

Sandy
 
Hi Jim

Thanks so much for your response

Cor Ligthert's solution worked beautifully in this case

Sandy
 
Hi Cor

Thanks! That works perfectly

Sand

----- Cor Ligthert wrote: ----

Hi Sandy

You mea
\\ dim mydate as dat
if isdate(textbox1.text) the
mydate=cdate(textbox1.text
end i
//
I hope this helps

Co
 
Dear Armin

Thanks so much for your response

Cor Ligthert's solution worked perfectly for this case

Sand

----- Armin Zingler wrote: ----

Sandy said:

Right. ;-) "Null" has no relation to strings and dates and textboxes
These textboxes are not connected to an
database. They are textboxes that can contain a DateTime value o
can contain nothing. I need code that essentially says "If th
textbox is empty, disregard the code that pertains to that textbox.
string "" to type 'Date' is not valid.
value if they were blank, that would work, but I don't know how to d
that

A date time value never contains only a time. It always contains a date an
a time. You could use DateTime.Minvalue, which is the 1st January 000
00:00, as a special date and time to represent what you need
As long as all the textboxes are filled in with a time, the cod
works. If some are left blank, I get the error

What about "If"

dim d as dat

If text1.text.length = 0 the
d = datetime.minvalu
els
'do the conversio
end i

As there might still be errors in the else block, I'd use a try/catch bloc
within the else block


--
Armi

How to quote and why
http://www.plig.net/nnq/nquote.htm
http://www.netmeister.org/news/learn2quote.htm
 
Hello Herfried

Thank you for responding.

Cor Ligthert's solution worked for my particular problem

Sandy
 
Back
Top