C# Class Design: ADO.NET, separating business logic from presentation, etc.

Posted on 2006-05-13
Last Modified: 2010-08-05
Hi Experts,

I am a C# novice trying to develop a simple DB application for use in my office, and I could use some expert advice with class deisgn. I am using VisualStudio 2005 and thus C# 2.0, and I will be using SQL Server as my DB.

I am trying to design the classes for this application, but I am having difficulty since this is my first try at a "no-spaghetti-code" design.

This app is to help me track Patients, Doctors, and any lab Tests that Doctors prescribe for their respective Patients.

What I'm concerned about is the interaction of presentation with business logic and data, and their (necessary ?) separation:

1: My DB has tables: 'Patients', 'Doctors', and 'Tests'

2: I have a WinForm named "Form1" (which VS 2005 creates as a class), and this WinForm has some textBoxes that will be bound to fields on the 'Patients' table, which will happen when "Form1" is loaded. In the past, I've just put the business logic code straight onto the "Form1" class...the Form would load and the textBoxes would be populated, and then I could navigate using other controls, etc. (see example below)

- - - - - - - - - - - - - - - - - - - - - -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataApp
    public partial class Form1 : Form
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            // establish connection to DB, 'Patients' table

            // retrieve data from record in 'Patients' table

            // bind data from 'Patients' fields to textBoxes on this "Form1"

- - - - - - - - - - - - - - - - - - - - - -

From reading about current programming models, it seems like the developer is being asked to design an additional class to represent a "Patient" record from the table (or to represent the 'Patients' table itself ??). In other words, it sounds like all my SqlConnection, DataSet, Get/Set methods, and all the code needed to access the records/ etc. need to be in another class?? Does this help clarify what I mean? In the past, I would have effectively made the WinForm "Form1" class my "Patient" class, but it seems like "n-tier" would mean separation of the WinForm class from the "Patient" class. If this is the case, how would I get the "Form1" class to interact with the "Patient" class to still have data-bound controls on "Form1" ?

I also am unsure about how to design classes for a DB. Do I need to create a class for every table in the DB, with attributes assigned for each field in a particular table?

Hopefully what I explained is not sounding like complete nonsense!

Thanks! :-)
Question by:crypto_monkey
    LVL 11

    Accepted Solution

    (For a full answer read the first two chapters to "Data Binding with Windows Forms 2.0" by Brian Noyes.)

    His advice would be to build a data layer dll which will give you a strongly typed, extensible, dataset, datatables, and tableadapters. You use the TableAdapters to control the interaction between the database and the dataset. You using Bindingsource objects to control the interaction between the UI and the dataset.

    There is surprisinglyu little code involved, and it is one hell of a lot easier to do with VS2005 than it was with VS2003.


    Author Comment


    Thanks for the info about the book and about the TableAdapters, etc. That was helpful to get me pointed in the right direction.

    I went looking on the web and didn't have any luck locating tutorials for such a process. Until I can free up some extra $$ to check out and possibly buy the book you mentioned, I have to make use of what info is available for free. Do you happen to know of any links to such material? Thanks.
    LVL 11

    Expert Comment

    You could try the free virtual labs here:

    Or, start here at the free training module "Course 2924: Building Data Components in Microsoft® Visual Studio® 2005":


    Author Comment


    I was able to take a lookat the Book you recommended, and it is indeed very informative. The second chapter tells me alot about the same type of scenario I had questions about. Thanks for the input, and thanks for the additional links, too.


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now