These two lines mean you're selecting record sets back from your SQL script
SELECT * FROM #directories
SELECT * From #instances
So that fact you using
ExecuteNonQuery
against your command object is a bit strange.
You can read anything you
SELECT
from an SQL command by using a
DataReader
IDataReader dr = cmd.ExecuteReader();
You then have the
dr.Read()
command which will return
true
until it reaches the end of the record set.
You also have
dr.NextResult()
which returns true until you run out of record sets.
This means you can access all the rows from multiple record sets from any SQL statement executed through ADO.