Connecting to SQL Server and 3 Tier Architectures

A Question on Object Orientation from a .Net Forum
And David Ringsell’s answers

How can I connect to a table in a SQL Server database?

There are several ways for an application to connect to a table in a SQL Server database.

The most basic approach, with an ASP.Net web form, is to use the gridview and datasource controls. The gridview control displays data, like a spreadsheet, in rows and columns. It can easily bind to data e.g. a database table.  With Net 2.0 the datasource control was introduced. This provides a simple Wizard to bind to a database by selecting it’s tables & columns. The datasource control  also provides automatic sorting, paging, updating and deleting in the gridview.

Alternatively the gridview can manually bind to an object e.g. a dataset. You then have to write event handler code for sorting, paging, updating and deleting.

The gridview also allows more advanced features,  like showing data hierarchically as parent and child rows. Or including extra controls, e.g.  adding checkboxes in a column.

You can also connect to a database using ADO.Net objects. This is a more versatile approach, that requires that you write more code. For this you need to create SqlConnection, SqlDataAdapter and SqlCommand objects. These allow you retrieve & update data in the database tables. The data can then be held within your application in a DataReader or DataSet object. Once in the application the data can be displayed and worked with.

Yet another approach is to use LINQ to SQL. This allows you to drag tables, views and stored procedures to a O/RM design surface. LINQ to SQL automatically creates the classes and collections for you. You can then run LINQ queries against the generated collections. To do this, you use a DataContext object that is created. To write changes back to the database, use the DataContext.SubmitChanges () method

Here is our tutorial on data access in C#.
http://talk-it.biz/data-access-using-visual-studio-2008

What is a 3 tier architecture?

The 3 tiers correspond with how we normally think of software behaving. The UI – interacting with users, the BL – applying business logic,  the DAL – storing data.

In the .Net world the tiers are developed as separate projects. Each project compiles to an assembly. Each assembly can then be deployed to a server.

The .Net projects can themselves be contained in a single solution. This makes it more possible to develop and debug the whole application.

The benefits of this include robustness, if one server fails, another can take over. Also performance is improved by sharing the work between different servers. There are load balancing techniques employed to distribute the demand  between servers.
There are now a range a different architectures that suit different types of application, e.g. MVC is popular for web applications. And MVVM works well for WPF applications.

Here is our tutorial on OOP in C#.
http://talk-it.biz/object-orientation-using-c-sharp

Scroll to Top