C# 如何在sql中包含null作为搜索参数
表格:C# 如何在sql中包含null作为搜索参数,c#,asp.net,sql,C#,Asp.net,Sql,表格: tblEmployee - EmployeeId, EmployeeName tblActivity - EmployeeId, AppraisalId <asp:dropdownlist id="ddlemployee" runat="server" appenddatabounditems="true"> <asp:listitem text="--All--" value="0"/> </asp:dropdownlist> <
tblEmployee - EmployeeId, EmployeeName
tblActivity - EmployeeId, AppraisalId
<asp:dropdownlist id="ddlemployee" runat="server" appenddatabounditems="true">
<asp:listitem text="--All--" value="0"/>
</asp:dropdownlist>
<asp:dropdownlist id="ddlappraisal" runat="server" appenddatabounditems="true">
<asp:listitem text="--All--" value="-1"/>
<asp:listitem text="None"/> //not sure what value this should have
<asp:listitem text="Excellent" value="2"/>
<asp:listitem text="Average" value="1"/>
<asp:listitem text="Poor" value="0"/>
</asp:dropdownlist>
alter procedure getdata
@EmployeeId int
@AppraisalId int
as
begin
set nocount on;
if @EmployeeId = 0
set @EmployeeId = null
select e.employeename,a.appraisalid
from tblemployee e
left join tblactivity a on
( e.employeeid = a.employeeid and
(e.employeeid = @Employeeid or @Employeeid is null) and
(a.appraisalid = @AppraisalId or @AppraisalId = -1)
)
end
列evaluvalid
的数据类型为int,其值为0-2
或NULL
这两个下拉列表中选定的值提供存储过程的参数
用户可以搜索所有员工的记录,也可以只搜索任何一名员工的记录。同样,对于所有评估,没有或任何一种类型的评估
如果我必须只搜索evalualid为NULL的记录,该怎么办。否则查询工作正常
ASPX:
tblEmployee - EmployeeId, EmployeeName
tblActivity - EmployeeId, AppraisalId
<asp:dropdownlist id="ddlemployee" runat="server" appenddatabounditems="true">
<asp:listitem text="--All--" value="0"/>
</asp:dropdownlist>
<asp:dropdownlist id="ddlappraisal" runat="server" appenddatabounditems="true">
<asp:listitem text="--All--" value="-1"/>
<asp:listitem text="None"/> //not sure what value this should have
<asp:listitem text="Excellent" value="2"/>
<asp:listitem text="Average" value="1"/>
<asp:listitem text="Poor" value="0"/>
</asp:dropdownlist>
alter procedure getdata
@EmployeeId int
@AppraisalId int
as
begin
set nocount on;
if @EmployeeId = 0
set @EmployeeId = null
select e.employeename,a.appraisalid
from tblemployee e
left join tblactivity a on
( e.employeeid = a.employeeid and
(e.employeeid = @Employeeid or @Employeeid is null) and
(a.appraisalid = @AppraisalId or @AppraisalId = -1)
)
end
您可以为“无”选项提供-2的值:
<asp:listitem text="None" value="-2"/>