Thursday, March 22, 2012

Check if SqlDataSource is Empty in CodeBehind

This is probably an easy one.

What is best way to determine if a SqlDataSource is empty (i.e. the query produced no results) in the CodeBehind?

I'm using this:

if (SqlDataSource1.SelectCommand.Contains(String.Empty))

{

//Add code for scenario here.

}

It seems to work, but something just doesn't feel right about it for some reason.

Thanks

Not sure if this is better than your method, but you can always handle the Selected event for your SqlDataSource control to find out how many rows were returned from the query:

protectedvoid SqlDataSource1_Selected(object sender,SqlDataSourceStatusEventArgs e)

{

int ct = e.AffectedRows;

}

|||I'm trying to do the exact thing. Any other alternatives?

No comments:

Post a Comment