【发布时间】:2012-06-19 15:46:39
【问题描述】:
我在 SqlDataSource 中有以下 selectcommand,我的问题是它只在我有两个参数的值时才返回数据。当只有 1 有值时,我还需要它来返回数据。
SelectCommand="SELECT user.UserId, UserProfiles.Company, UserProfiles.Address, UserProfiles.JV2, UserProfiles.DB1, aspnet_Membership.Email, user.UserName
FROM user INNER JOIN UserProfiles ON user.UserId = UserProfiles.UserId WHERE (@UserName IS NULL OR @UserName = '' OR user.UserName LIKE '%'+@UserName+'%' ) AND
(@Email IS NULL OR @Email = '' OR user.Email LIKE '%'+@Email+'%')
使用以下参数
<SelectParameters>
<asp:ControlParameter Name="Email" ControlID="eMail" PropertyName="Text" Type="String" />
<asp:ControlParameter Name="UserName" ControlID="userName" PropertyName="Text" Type="String" />
当我在 SQL Server Management Studio 中运行查询时,它会在我只输入 1 个值或两者时返回数据。 当我运行表单时,只有在两个字段中输入值时才会返回数据。
我发现了这篇文章:SqlDataSource SelectCommand using LIKE does not work,这很相似,但解决方案没有帮助。
显然我做错了什么,我只是看不出是什么。
【问题讨论】:
标签: asp.net sql sqldatasource