Please see my question in a comment to the question. Apparently, if you don't get data at all, you have no data, so the question does not make complete sense.
You have a command, now you can create either
System.Data.SqlClient.SqlDataReader
or
System.Data.SqlClient.SqlDataAdapter
out of it. If you use a data adapter, you still need to fill the data in the data set or data table. If you have data reader, you only can check up it it has rows (the method
HasRows
), but you still need to read the data to see how many of them do you have. Perhaps this method would be the closest to the vague idea of "prior to getting the data":
SqlConnection =
string queryString = "Select Count(*) as Fred from Table";
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
int rowCount = 0;
if (reader.HasRows)
while (reader.Read()) ++rowCount;
reader.Close();
Please see:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx[
^].
—SA