jul*_*lio 5 vb.net asp.net sqldatasource
我有一个asp.net页面,其中有几个已SqlDataSources定义,将数据提供给一些图表.图形产品不能正常处理"无数据",并抛出异常.我想要这样处理这种情况 - 所以我需要SqlDataSource在渲染图形之前检查返回的数据(如果没有,只需发布一条消息说"无数据"或其他东西).
有没有一种简单的方法可以检查数据源是否返回数据,并且如果/然后没有一堆代码,那么这样做?
Jac*_*tti 14
以下是取自devcurry,这几乎是你正在寻找的.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName],
[ContactTitle], [Address] FROM [Customers]"
onselected="SqlDataSource1_Selected">
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
在代码背后:
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
If e.AffectedRows < 1 Then
' perform action
End If
End Sub
Run Code Online (Sandbox Code Playgroud)