This is a simplification of the issue (there are lots of ways of doing things), but among applications that need to talk to a database I have usually seen one of two patterns:
- Object-Relational Mapping (ORM), where (usually) each table in the database has a corresponding "row wrapper" class with public properties that match the columns in the table. Sometimes these classes also automagically retrieve related information, so that foreign key columns can instead be exposed and displayed as the related data (rather than just the PK values).
- DataTables (and/or DataSets), where data is retrieved from the server as a DataTable and worked with in that form (even in the UI).
One of the major differences between the two approaches is that ORM allows you to reference strongly-typed fields in your code like so:
Person bob = new Person();
bob.FirstName = "Bob";
collectionPeople.Add(bob);
whereas with the DataTable approach your code would be something like:
DataRow newrow = datatablePeople.NewRow();
newrow["FirstName"] = "Bob";
datatablePeople.Rows.Add(newrow);
In this case, the ORM approach benefits from compile-time checking while the DataTable approach does not. On the other hand, the DataTable (and the DataSet) are already-written data structures that do an excellent job of representing relational data directly, so code that uses them can usually be implemented more quickly. In addition, code that uses DataTables can be easily understood and modified by others; home-grown (and often COTS) ORM systems often do extra database access "under the hood" to populate foreign keys and so forth, which can create problems for the unaware.
So which approach do you generally favor and why?