You should use CURSOR in you stored procedure like this:
DECLARE @foo VARCHAR(XXX)
DECLARE Curs CURSOR FAST_FORWARD READ_ONLY FOR
SELECT
foo
FROM sometable
WHERE
somecolumn = @parameter
OPEN Curs
FETCH NEXT FROM Curs INTO @foo
WHILE @@FETCH_STATUS = 0
BEGIN
-- here you should put actual query
SELECT
*
FROM dbo.SomeTable
WHERE
foo = @foo
FETCH NEXT FROM Curs INTO @foo
END
CLOSE Curs
DEALLOCATE Curs
and then read cursor results using code like:
var sqlCommand = new SqlCommand("spYourStoredProcedure", connection)
sqlCommand.CommandType = CommandType.StoredProcedure;
var reader = sqlCommand.ExecuteReader();
do
{
while (reader.Read())
{
// DO SOMETHING
}
} while(reader.NextResult());