title: Executing SQL commands as nested loop of SQL command
body: <p>I am building a function that uses a SQL query to get a list of tables to drop. Then I want to iterate through each resulting row and execute the command.</p>
  
  <pre><code>Public Shared Sub DropTables(DbConnectionString As String)
      Dim sqlConnection As New SqlConnection(DbConnectionString)
      Dim cmd As New SqlCommand
      Dim reader As SqlDataReader
      cmd.CommandText = "SELECT 'DROP TABLE ' + name + ';' from sysobjects where name like 'SM_%' and type='U';"
      cmd.CommandType = CommandType.Text
      cmd.Connection = sqlConnection
      sqlConnection.Open()
      reader = cmd.ExecuteReader()
      If reader.HasRows Then
          Do While reader.Read()
              Using nonQuery As SqlCommand = sqlConnection.CreateCommand()
                  nonQuery.CommandText = reader.GetString(0)
                  nonQuery.ExecuteNonQuery()
              End Using
          Loop
      Else
          Console.WriteLine("No rows found.")
      End If
      sqlConnection.Close()
  End Sub
  </code></pre>
  
  <p>My issue is that I am getting an this error on this line: <code>nonQuery.ExecuteNonQuery()</code></p>
  
  <pre><code>There is already an open DataReader associated with this Command which must be closed first.
  </code></pre>
  
  <p>But I am using a different data reader.</p>