Simplicity over Complexity
Today I was working on a reporting feature for an ASP.NET application I develop/manage at work and came across an interesting design decision. Per the request of the users of the application, I am adding the ability to export reports to an excel file but I only wanted to display the basic information for each record that will be exported. The library that I am using to export the data is the EPPlus library which makes it really easy to export data to Excel 2007/2010. All you need to do is pass an object that implements IEnumerable
At first I though of creating a custom object that will then be used to load up a List
The decision to return a DataSet object turned out to be the best one as this was not only the simplest solution, but also it turned out to be more flexible than I had imagined! Being able to make changes to the SQL Query on the fly to get only the data I want is great! I would not have been able to do this with a custom object which makes my job as the developer that much easier! Below is the method signature I ended up writing:
Notice how I used the word DataSet in the name of the method and also added a comment to remind me that this will be used in an excel worksheet. I always strive to write code that is simple and easy to maintain and this solution adheres to this rule of mine!
Leave a comment