允许为空 [英] Allow Null

查看:121
本文介绍了允许为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆文本框,可以让它们为空


如何编程呢?我一直收到错误,说Null不再支持


Sandy

解决方案

" Sandy" <一个******* @ discussions.microsoft.com> schrieb

我有一堆文本框,它们可以是
null。

如何编程?我一直收到一个错误,说Null没有得到更长时间的支持。




你在谈论数据库中的Null值吗?它由

DBNull.Value表示。您无法将DBNull设置为文本框。一个文本框只包含

a字符串(长度0到

远远超过你可以读取和写入并且适合你的内存-without-swappi

ng-five-days-long)。我想说什么?...啊,好的:你/可以/使用

特殊字符串,比如(Null)表示文本框中的Null值,但仅当此特殊字符串永远不是

数据库中的正常字段内容时才会显示
。即使它不是非常用户友好,因为用户可以输入
来输入这个字符串来存储Null值。我可能会在文本框前面使用一个复选框

(没有文字)。如果选中,则文本框内容为

存储在数据库中,否则存储空值。

-

Armin


如何报价以及原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


嗨Armin


我想我不太清楚。这些文本框未连接到任何数据库。它们是可以包含DateTime值的文本框,或者不包含任何内容。我需要的代码基本上是如果文本框为空,请忽略与该文本框相关的代码。


生成的错误是:System.InvalidCastException。从字符串"中删除键入''Date''无效。


如果我发现文本框默认为00:00:00时间值,如果它们是空白的话,那就行了,但我不知道该怎么做


只要所有文本框都填充了一段时间,代码就可以了。如果有些空白,我会收到错误


任何想法


Sandy


< blockquote>嗨桑迪,


你的意思是

\\\

dim mydate as date

if isdate(textbox1.text)然后

mydate = cdate(textbox1.text)

结束如果

///

我希望这有帮助吗?


Cor


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" <an*******@discussions.microsoft.com> schrieb

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


这篇关于允许为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆