SqlDataSource SelectCommand using LIKE does not work

China☆狼群 提交于 2019-12-03 23:05:24

I would do something like:

where (@business is null
          or @business = ''
          or h.Business like '%' + @business + '%')
      and (@frn is null
              or @frn = ''
              or hrl.frn = @frn)

If you make your empty search strings nulls before passing them, you can skip the @yyy = '' part.

Change

"and h.Business is not null"

to

"or h.Business is null"

and

"and hrl.frn is not null"

to

"or hrl.frn is null"

That will return everything when those parameters are null.

"and is not null"

The stored procedures have it right: (@frn IS NULL OR hrl.frn = @frn). You want to select any line either if frn is null or it matches. The same pattern is applicable to the business property.

NullReferenceException

sqlDsMaster.SelectParameters[frn].DefaultValue = frn;

This fails, because you are using the value of the frn property (which may be null) instead of the string "frn" as index into the SelectParameters. You have the same error on the next line with business instead of "business".

ConvertEmptyStringToNull

I would pose the question the other way round: if you're using ConvertEmptyStringToNull, why would you want to burden the caller with the same functionality? Unless the empty string would be a valid value for frn or business, I'd leave ConvertEmptyStringToNull set and not care about it in the caller.

I hope that answers all your questions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!