Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I check that a SqlDataSource returned data?

I have an asp.net page that has several SqlDataSources defined that feed data into some graphs. The graph product does not handle "no data" gracefully, and throws an exception. I'd like this to handle the situation -- so I need to check whether the SqlDataSource returned data before rendering the graph (and if not, just post a message saying "No Data" or something).

Is there an easy way to check if the data source returned data, and do this if/then without a bunch of code behind?

like image 548
julio Avatar asked Feb 09 '10 18:02

julio


2 Answers

The following is taken from devcurry, which is pretty much what you are looking for.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName],
    [ContactTitle], [Address] FROM [Customers]"
    onselected="SqlDataSource1_Selected">
</asp:SqlDataSource>

And in code behind:

Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)

    If e.AffectedRows < 1 Then

        ' perform action

    End If

End Sub
like image 116
Jack Marchetti Avatar answered Oct 01 '22 22:10

Jack Marchetti


try this http://www.devcurry.com/2009/02/how-do-you-check-if-sqldatasource.html

i hope if it helps you ..

like image 37
Amr Elnashar Avatar answered Oct 02 '22 00:10

Amr Elnashar