Please see my comment to the question.
To make sure the data set obtained through the query in not empty, create a data reader and check it. Data reader is agnostic to the database schema, it can show you the complete result of the query.
For example:
string queryText =
SqlCommand command = new SqlCommand(queryText);
SqlDataReader reader = command.ExecuteReader();
boo empty = !reader.HasRows;
reader.Close();
The data reader is very convenient when you only start to work with some database and may want to investigate what's in it and validate the structure of data sets you are going to create. Please see:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx[
^].
There is another problem, a bigger one.
You are composing your query as a string from the UI. Not only this is bad architecture, this is very bad and absolutely
not acceptable from the security stand point. You system
can be easily intruded using SQP Injection. Please see:
http://en.wikipedia.org/wiki/SQL_injection[
^].
In the article referenced above, read about importance of
parametrized statements, see also:
http://en.wikipedia.org/wiki/Prepared_statement[
^].
Other parameters of the query (those written in Arabo-Persian script, if I'm not mistaken), are now hard-coded, but sooner or later you will have to parametrize them, and that will bring you to the same problem.
To do it in a safe, consistent and maintainable way, you should use
parametrized commands, nothing else. Please see:
http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx[
^].
—SA