gpt4 book ai didi

asp.net - SqlDataSource SelectCommand 使用 2 个参数和 LIKE 不起作用

转载 作者:行者123 更新时间:2023-12-04 18:18:57 25 4
gpt4 key购买 nike

我在 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这是相似的,但解决方案没有帮助。

显然我做错了什么,我只是看不出是什么。

最佳答案

我有一个类似的问题并将其添加到 sqldatasource 修复它:

<asp:SqlDataSource CancelSelectOnNullParameter="false">

关于asp.net - SqlDataSource SelectCommand 使用 2 个参数和 LIKE 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11104638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com