使用 sqldatasource 时 asp.net C# 加载时间缓慢
我需要提供一个包含三个过滤器的报告,例如
select * from foo where condition 1 and condition 2 and condition 3
“所以我正在使用对象数据源并将三个参数绑定到三个不同的下拉列表,它效果很好,但是我被问到下拉列表中的第一个选项将是“全部”——意味着没有过滤器。 因为我知道如何仅使用 sqldata 源来做到这一点,所以我切换了控件并使用了以下代码
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [Tickets_data] ORDER BY [Open_Time]"
FilterExpression="[Lote] like '{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="DropLote" Name="Lote" PropertyName="SelectedValue" Type="String"/>
</FilterParameters>
</asp:SqlDataSource>
它正在工作,但加载时间非常慢,如 9 或 10 秒,并且下拉列表中的每次刷新也非常慢。
有什么建议吗?
I need to present a report that has three filters something like
select * from foo where condition 1 and condition 2 and condition 3
So I'm using an object datasource and bound the three parameters to three different drop downs and it works great, however I've been asked that the first option in the drop down would be "All" - meaning no filter.
Since i know how to do it only with sqldata source I switched the control and used the following code
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [Tickets_data] ORDER BY [Open_Time]"
FilterExpression="[Lote] like '{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="DropLote" Name="Lote" PropertyName="SelectedValue" Type="String"/>
</FilterParameters>
</asp:SqlDataSource>
It's working, but loading time is very slow like 9 or 10 seconds, and each refresh in the dropdown is also extremly slow.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您在使用以下行时遇到了麻烦:
当参数为空时 - SqlServer 将每个简单记录与“%”进行比较。在这种情况下,您可以尝试将 sql 语句修改为:
当 {0} 为空时,这将使 SQL Server 仅计算第一部分并跳过第二部分(如“{0}%”)。
但对于未来,我建议不要直接从 UI 接触 sql 语句,这可能会使您的应用程序在某些时候变得非常僵化。因此,您可以将所有内容移至代码隐藏(更好的是移至代码隐藏后面,移至数据访问层)。
Looks like you've got troubles with the line:
when parameter is empty - SqlServer compare every simple record with '%'. In that case you could try hacking sql statement to:
which would make SQL server to evaluate only first part and skip the second one (like '{0}%') when {0} is empty.
But for future I'd suggest not touching sql statements from UI directly, that could make your application very rigid at some point. So you move everything to codebehind (and even better behind the codebehind, to Data Access Layer).