Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在sql中包含null作为搜索参数_C#_Asp.net_Sql - Fatal编程技术网

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"/>