This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
It's quite rare that you really need every column from every record in a given table for a DB application, and fetching unnecessary data just adds extra work and uses up bandwidth. Select specific columns, and only for the records you want i.e. use a WHERE clause wherever possible.
Another problem with "SELECT * ..." is that the table structure may change. Columns may be added/removed from the table, or the column names/data types might change, but there's nothing in your SQL statement to tell the next programmer whether they need to change your SQL to take account of these changes. Make your intentions for your SQL query explicit - select specific columns by name - so that maintaining the program is easier when (not if) the DB changes.
Along with the good advice from Chris, the style of option 2 is definitely the way to go. You don't want calling code to have to know about SQL strings or result sets. It simply needs to provide the ID of the customer to retrieve and the method does the rest.
Joined: Aug 02, 2012
got it, thanks
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: What is the preferred way of coding the database?