我有一个页面可以查看所有大学,我希望这个页面可以查看按城市过滤的数据,我添加到 SQL 语句中:
WHERE (Cit_Id = @Unv_CitId OR @Unv_CitId IS NULL)
并将 @Unv_CitId 参数的 DefaultValue 设置为 NULL,但出现错误,
我该如何解决这个问题?
您应该分配 valueDBNull.Value
而不是null
.
you can try this
where (Cit_Id = isdbnull(@Unv_CitId)?null:@unv_citId
I'm not 100% sure of your intention, but what about something like this:
WHERE (Cit_Id = @Unv_CitId OR Cit_Id IS NULL)
Your original query looks a little odd with @Unv_CitId IS NULL
in there: this clause isn't checking against a field, merely against the value being passed in.
delclare @Unv_CitId as null 同时在过程中声明参数,如下所示
@Unv_CitId int NULL
所以变量也将接受空值。
是的现在可以了,我将SqlDataSource的CancelSelectOnNullParameter属性设置为False,并删除参数的defaultValue