实体数据源,其中NOT IN

时间:2012-08-08 11:32:21

标签: c# sql

我需要正确的语法来完成这项工作。

修改

XAML:

<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=Entities"
            DefaultContainerName="Entities" EnableDelete="True" EnableFlattening="False"
            EnableInsert="True" EnableUpdate="True" EntitySetName="Plans" AutoGenerateWhereClause="true">
             <WhereParameters>
                <asp:ControlParameter ControlID="tbxSearch" Name="Name" Type="String" />
            </WhereParameters>
</asp:EntityDataSource>

代码背后:

if (string.IsNullOrEmpty(tbxSearch.Text))
{
   this.EntityDataSource1.Where = 
     "NOT it.Id IN (SELECT Id FROM Plans_PendingChange) ";//getting all the records instead of getting the proper records
}
else
{
   this.EntityDataSource1.Where = "it.Name =  @Name ";
}

1 个答案:

答案 0 :(得分:2)

尝试使用NOT it.Id IN代替it.Id NOT IN,如下所示:

this.EntityDataSource1.WhereParameters.Clear();
if (string.IsNullOrEmpty(tbxSearch.Text))
{
   this.EntityDataSource1.Where = "NOT it.Id IN (SELECT Id FROM Plans_PendingChange) ";
}
else
{
   this.EntityDataSource1.Where = "it.Name =  @Name ";
}