1

我有一个页面可以查看所有大学,我希望这个页面可以查看按城市过滤的数据,我添加到 SQL 语句中:

WHERE (Cit_Id = @Unv_CitId OR @Unv_CitId IS NULL)

并将 @Unv_CitId 参数的 DefaultValue 设置为 NULL,但出现错误,

我该如何解决这个问题?

4

5 回答 5

3

您应该分配 valueDBNull.Value而不是null.

于 2012-10-23T05:11:06.050 回答
0

you can try this

where (Cit_Id = isdbnull(@Unv_CitId)?null:@unv_citId
于 2012-10-23T05:27:23.060 回答
0

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.

于 2012-10-23T05:29:38.173 回答
0

delclare @Unv_CitId as null 同时在过程中声明参数,如下所示

@Unv_CitId int NULL

所以变量也将接受空值。

于 2012-10-23T07:18:39.397 回答
0

是的现在可以了,我将SqlDataSource的CancelSelectOnNullParameter属性设置为False,并删除参数的defaultValue

于 2012-10-23T06:09:12.870 回答