I have this:
countReader = command7.ExecuteReader();
while (countReader.Read())
{
string countName = countReader["count(*)"].ToString();
}
How to get string countName outside while loop?
You could declare it in the outer scope:
countReader = command7.ExecuteReader();
string countName = "";
while (countReader.Read())
{
countName = countReader["count(*)"].ToString();
}
// you can use countName here
Note that because you are overwriting its value on each iteration, outside the loop you will get its value from the last iteration or an empty string if the loop didn't execute.
"count(*)"? That doesn't look like a valid column name to me. Are you trying to get the sum of that column? If not, what are you trying to accomplish?