整数如何包含空值? [英] How Can an Integer Contain a Null Value?

查看:85
本文介绍了整数如何包含空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整数具有空值意味着什么?我试图使用

DataView.Find方法。该方法有一个整数返回类型,

包含DataView中包含排序键值

指定的行的索引;否则,如果排序键值不存在,则为空值。


按空值,是否表示System.DBNull? (我以为只有对象可以

求值为System.DBNull。)如何测试整数变量是否持有

a null值?

- TC

What does it mean for an integer to have a null value? I am trying to use
the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value
specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could
evaluate to System.DBNull.) How can I test whether an integer variable holds
a null value?
-TC

推荐答案

Hi TC,
整数具有空值意味着什么?我正在尝试使用DataView.Find方法。该方法有一个整数返回类型,它包含DataView中包含排序键
值的行的索引;否则,如果排序键值不存在,则为空值。

按空值,是否表示System.DBNull? (我认为只有对象可以评估为System.DBNull。)如何测试整数变量
是否包含空值?
What does it mean for an integer to have a null value? I am trying to use
the DataView.Find method. That method has an integer return type which
contains the "index of the row in the DataView containing the sort key value specified; otherwise a null value if the sort key value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects could
evaluate to System.DBNull.) How can I test whether an integer variable holds a null value?




我对答案的第一个想法是价值永远不会是没有。或者

" dbnull" ;.


(这是危险的东西,因为我曾经在这里争论过什么是

对于英语很难,然后我通过实例说定义

这样的单词就像null一样。)


所以不要太多关于我的话使用,只是意思。


然后我看到你可能正在谈论一个数据库整数,什么

是一个完全不同的东西。它是整数的占位符。那可以是

空或者dbnull


在你的消息下面你会看到一条带有executeScalar的消息。


Sthephany昨天发送了一个关于drygast如何使用它的例子。我昨天第一次看到了它的答案,我也不知道它是否适合我的b $ b。对我来说,我认为确实如此。


我把它贴在下面


\\\

您正在使用一个阅读器,如果它存在,它将有一个记录,如果它不存在,它将没有记录。你的问题在于,当读者没有记录时你没有处理这种情况。


改变跟踪并使用ExecuteScalar()对抗命令对象

,sql更改为:

从[order]中选择count(*),其中ordernummer =" &安培; txtOrdernummer.Text


如果订单存在,结果将为1,如果不存在则结果为0.


因此测试变为:


如果cmd.ExecuteScalar()= 0那么

''订单不存在

否则

''订单确实存在

结束如果

///

我希望这有点帮助。


Cor



My first thought of the answer was a value can never be "nothing" or
"dbnull".

(This is dangerous stuff, because I once had an argue here about what is
difficult about English language and then I said by instance the definition
of words like null.)

So don''t look to much on the words I use, just at the meaning.

But then I saw that you are probably talking about a database integer, what
is a total different thing. It is a placeholder for an integer. That can be
empty or dbnull

Just beneath your message you see a message with executeScalar.

Sthephany did send yesterday an example for drygast how to use that. I saw
it yesterday too the first time for the answer beneath I don''t know if it
fit. For you I think it does.

I pasted it in beneath

\\\
You are using a reader and that will have a record if it exist and it will
have no records if it does not exist. Your issue is with the fact that you
are not handling the situation when the reader has no records.

Change track a little and use ExecuteScalar() against the command object
with the sql changed to:

select count(*) from [order] where ordernummer=" & txtOrdernummer.Text

The result will be 1 if the order exists and 0 if it does not.

So the test becomes:

If cmd.ExecuteScalar() = 0 Then
'' Order does not exist
Else
'' Order does exist
End If
///
I hope this helps a little bit.

Cor


" TC" < q@w.e> schrieb
"TC" <q@w.e> schrieb
整数具有空值意味着什么?我正在尝试使用DataView.Find方法。该方法具有整数返回类型
,其中包含DataView中包含指定的
排序键值的行的索引;如果排序键
值不存在,则为null值。

按空值,是否表示System.DBNull? (我认为只有对象可以评估为System.DBNull。)如何测试整数
变量是否包含空值?
What does it mean for an integer to have a null value? I am trying to
use the DataView.Find method. That method has an integer return type
which contains the "index of the row in the DataView containing the
sort key value specified; otherwise a null value if the sort key
value does not exist."

By "null value", does it mean System.DBNull? (I thought only objects
could evaluate to System.DBNull.) How can I test whether an integer
variable holds a null value?




单词null根据具体情况,可以有两种不同的含义。在

框架和CLR(docs)中,Null是无引用的术语。

VB.NET中的等效术语是Nothing。当谈论空时在一个

数据库中,它意味着DBNull(相应的DBNull.Value)。当您从处理数据库内容的框架收到消息时,可能会感到困惑。在这个

的情况下,我们必须聪明地认识到

Null这个词是什么意思。


在VB.NET上下文中说话:Integer变量既不能是Nothing也不能是
,也不能是DBNull。 (在C#上下文中我不得不说:一个整数变量

既不能为空也不能为DBNull)。每当变量与数据库值相关时,它可以是DBNull或整数,类型必须是

" Object"。只有声明为Object的变量才能包含DBNull或

(盒装)整数。你不能将一个Integer变量设置为DBNull(你可以将
设置为Nothing,但这等于将它设置为零(实际上它是

不应该被允许,因为它只是令人困惑))。如果变量是

声明为Object,你可以使用


如果theValue是DBNull.VAlue那么

msgbox"数据库字段包含Null

else

msgbox theValue

结束如果


第一个msgbox也可以显示

msgbox"数据库字段包含DBNull"

但在给定的上下文中(数据库字段...),它足以显示

" Null"在消息中。

-

Armin



The word "null" can have two different meanings depending on the context. In
the Framework and for the CLR (docs), Null is the term for "no reference".
The equivalent term in VB.NET is Nothing. When talking about "Null" in a
database, it means DBNull (resp. DBNull.Value). It might get confusing when
you get a message from the framework that deals with database stuff. In this
case, we have to be clever enough to recognize what is meant by the word
"Null".

Talking in the VB.NET context: An Integer variable can neither be Nothing
nor it can be DBNull. (in a C# context I''d have to say: An Integer variable
can neither be Null nor it can be DBNull). Whenever the variable is related
to a database value and it can be DBNull or an Integer, the type must be
"Object". Only variables declared as Object can either contain DBNull or a
(boxed) Integer. You can not set an Integer variable to DBNull (you could
set it to Nothing, but that''s equal to setting it to zero (and actually it
should not be allowed because it''s only confusing)). If the variable is
declared as Object, you can use

If theValue Is DBNull.VAlue then
msgbox "database field contains Null"
else
msgbox theValue
end if

The first msgbox could also show
msgbox "database field contains DBNull"
but in the given context ("database field...") it''s sufficient to show
"Null" in the message.
--
Armin


TC,

除了其他评论之外。


根据David Sceppa的书Microsoft ADO.NET - Core Reference和来自

MS Press,DataView.Find如果找不到所需的行,则返回-1。这与

一致,与框架中的其他类似搜索类型方法一致。


运行快速测试确认DataView.Find在键时返回-1

找不到。


如果您使用的是ADO.NET,我会推荐David的书。


希望这有帮助

Jay


" TC" < q@w.e>在消息新闻中写道:W5Mib.4869
TC,
In addition to the others comments.

According to David Sceppa''s book "Microsoft ADO.NET - Core Reference" from
MS Press, DataView.Find returns -1 if the desired row is not found. Which is
consistent with other similar searching type methods found in the framework.

Running a quick test confirms that DataView.Find returns a -1 when the key
is not found.

If you are using ADO.NET, I would recommend David''s book.

Hope this helps
Jay

"TC" <q@w.e> wrote in message news:W5Mib.4869


这篇关于整数如何包含空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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