重构我的数据阅读器以使用多个表

时间:2012-02-02 15:33:57

标签: c#

如何改进此方法以使其适用于多个表?

   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());
                   }
               }
           }
       }
   }

我可以回复读者(但我认为这意味着我必须删除我的使用语句)。或者,我可以根据我添加到ExecuteStoredProcedure()的参数创建一个处理每个表的工厂。管他呢。

如何在这里获取读者功能?