null参数问题 [英] Problem with null parameter

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

问题描述




我有一个带有以下SQL的datadapter;


SELECT ID,公司,状态,公司类型

FROM Companies

WHERE(@Status IS NULL或@Status = Status)


当我尝试这样填充时;

Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients," Current"),它带来所有

公司的状态为Current。


问题是,当我使用

Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,DBNull.Value.tostring)来填充

带来所有公司无论身份如何,那么而不是得到所有

公司我什么也得不到。我怎样才能解决这个问题?


谢谢


问候

Hi

I have a datadapter with the following SQL;

SELECT ID, Company, Status, CompanyType
FROM Companies
WHERE (@Status IS NULL or @Status = Status)

When I try to fill like so;
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, "Current"), it brings all
companies with status Current.

The problem is that when I fill using
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, DBNull.Value.tostring) to
bring all companies regardless of status, then instead of getting all
companies I get nothing. How can I get this fixed?

Thanks

Regards

推荐答案

John< Jo ** @ nospam.infovis.co.uk>写道:
John <Jo**@nospam.infovis.co.uk> wrote:
我有一个带有以下SQL的datadapter;

SELECT ID,公司,状态,公司类型
FROM Companies
WHERE(@Status IS NULL或@Status =状态)

当我尝试像这样填充;
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,Current),它带来所有
状态为Current的公司。

问题是,当我使用
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,DBNull.Value.tostring)填写
时无论身份如何,所有公司都会被带到公司,而不是让所有的公司都得到我的一切。我怎样才能解决这个问题?
I have a datadapter with the following SQL;

SELECT ID, Company, Status, CompanyType
FROM Companies
WHERE (@Status IS NULL or @Status = Status)

When I try to fill like so;
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, "Current"), it brings all
companies with status Current.

The problem is that when I fill using
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, DBNull.Value.tostring) to
bring all companies regardless of status, then instead of getting all
companies I get nothing. How can I get this fixed?




嗯,这正是你所要求的。当@Status为null时,

你的WHERE子句是:


WHERE(NULL是NULL或NULL =状态)


现在,第二个条款显然从来都不是 - 但第一个是

*总是*真!

我*怀疑*你的意思是:


WHERE(@Status IS为空且状态为空)或(@状态=状态)


-

Jon Skeet - < sk *** @ pobox.com>
http:// www .pobox.com / ~silet 博客: http://www.msmvps .com / jon.skeet

如果回复小组,请不要给我发邮件



Well, it''s doing exactly what you''ve asked it to. When @Status is null,
your WHERE clause is:

WHERE (NULL IS NULL OR NULL = Status)

Now, the second clause is obviously never true - but the first one is
*always* true!
I *suspect* you meant:

WHERE (@Status IS NULL AND Status IS NULL) OR (@Status=Status)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too




我*是*正在寻找子句WHERE(NULL IS NULL或NULL = Status)以便

为@status发送空值并带回所有

记录。问题是它没有返回!


谢谢


问候


" Jon Skeet [ C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP *********************** @ msnews.microsoft.co m ...

I *am* looking for the clause WHERE (NULL IS NULL OR NULL = Status) so that
it is true for when null value is sent for @status and brings back all
records. Problem is it is returning none!

Thanks

Regards

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
John< Jo ** @ nospam.infovis.co.uk>写道:
John <Jo**@nospam.infovis.co.uk> wrote:
我有一个带有以下SQL的datadapter;

SELECT ID,公司,状态,公司类型
FROM Companies
WHERE(@Status IS NULL或@Status =状态)

当我尝试填充时;
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,Current),它带来了
所有
公司状态为Current。

问题是,当我填写使用
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,DBNull.Value.tostring)<无论身份如何,所有公司都会被带到所有公司,而不是得到所有公司,我什么也得不到。我怎样才能解决这个问题?
I have a datadapter with the following SQL;

SELECT ID, Company, Status, CompanyType
FROM Companies
WHERE (@Status IS NULL or @Status = Status)

When I try to fill like so;
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, "Current"), it brings
all
companies with status Current.

The problem is that when I fill using
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients, DBNull.Value.tostring)
to
bring all companies regardless of status, then instead of getting all
companies I get nothing. How can I get this fixed?



好吧,它正在按照你的要求去做。当@Status为null时,你的WHERE子句是:

WHERE(NULL是NULL或NULL =状态)

现在,第二个子句显然永远不会是真的 - 但第一个是
*总是*真的!

我*怀疑*你的意思是:

WHERE(@Status IS NULL和Status IS NULL)或者(@状态=状态)

- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet
如果回复该群组,请不要给我发邮件



Well, it''s doing exactly what you''ve asked it to. When @Status is null,
your WHERE clause is:

WHERE (NULL IS NULL OR NULL = Status)

Now, the second clause is obviously never true - but the first one is
*always* true!
I *suspect* you meant:

WHERE (@Status IS NULL AND Status IS NULL) OR (@Status=Status)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too



John< Jo ** @ nospam.infovis.co.uk>写道:
John <Jo**@nospam.infovis.co.uk> wrote:
我*正在寻找WHERE(NULL IS NULL或NULL = Status)子句,以便当为@status发送空值并将所有值带回时,它是真的
记录。问题是它没有返回!
I *am* looking for the clause WHERE (NULL IS NULL OR NULL = Status) so that
it is true for when null value is sent for @status and brings back all
records. Problem is it is returning none!




我道歉 - 我误读了你以前的帖子。


嗯 - 你放了吗SQL Server上的探查器,用于检查查询中实际提交的值是多少?
?恐怕我现在不能轻易测试一下这个价格。


-

Jon Skeet - < sk *** @ pobox.com>
http:// www .pobox.com / ~silet 博客: http://www.msmvps .com / jon.skeet

如果回复小组,请不要给我发邮件



I do apologise - I misread your previous post.

Hmm - have you put a profiler onto SQL Server to check what value is
actually being submitted in the query? I''m afraid I can''t easily test
it myself at the moment.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于null参数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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