本文介绍了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

推荐答案




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

你的WHERE子句是:


WHERE(NULL是NULL或NULL =状态)


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

*总是*真!

我*怀疑*你的意思是:


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


-

Jon Skeet - < sk *** @ pobox.com>
博客:

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



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




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

WHERE(NULL是NULL或NULL =状态)

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

我*怀疑*你的意思是:

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

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



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






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


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


-

Jon Skeet - < sk *** @ pobox.com>
博客:

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



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参数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:15