P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

Refactor my data reader to work with multiple tables

How can I improve this method so that it works with multiple tables?

   public void ExecuteStoredProcedure(string StoredProcedureName)
   {
       using (var connection = new SqlConnection(provider.ConnectionString))
       {
           using (var command = new SqlCommand(StoredProcedureName, connection))
           {
               command.CommandType = System.Data.CommandType.StoredProcedure;
               using (var reader = command.ExecuteReader())
               {
                   while (reader.Read())//problem is here
                   {
                       Console.WriteLine(reader[0].ToString());
                   }
               }
           }
       }
   }

I could return the reader (but I think that means I'd have to drop my using statements). Or, I could create a factory that processes each table depending on a parameter that I add to the ExecuteStoredProcedure(). Or whatever.

How can I get the reader functionality outta here?

Upvotes: 0

Views: 594

Answers (1)

Related Questions