Friday, December 12, 2008

Date Formatting in VB.Net

Lets take the following example to know all the possible Date formatting in VB.Net.

CODE:

Dim op As New StringBuilder
Dim currerntDate As Date = Date.Now
op.AppendLine("Date Format Example)
op.AppendLine("Day in integer : " + Format(currerntDate, "dd") )
op.AppendLine("Day in string : " + Format(currerntDate, "dddd"))
op.AppendLine("Month in integer : " + Format(currerntDate, "MM"))
op.AppendLine("Month in string : " + Format(currerntDate, "MMMM"))
op.AppendLine("Year in integer : " + Format(currerntDate, "yy"))
op.AppendLine("Year in integer : " + Format(currerntDate, "yyyy"))
Response.Write(op)

OUTPUT

Date Format Example

Day in integer : 11
Day in string : Thursday
Month in integer: 12
Month in string : December
Year in integer : 08
Year in integer : 2008

Saturday, December 6, 2008

Database Normalisation

What is Database Normalisation?
Normalization is the process of organizing data in a database.

Normalisation process achieves,
a. Elimination of redundant data (Hence storage space reduced).
b. Ensure data dependency makes sense (Hence ensures data stored logically).

Database Normalisation is achieved by applying some rule called "Normal Form"

There are various levels of normalisation that can be done on databases,

1. First Normal Form:
a. Eliminate repeating groups in individual tables.
b. Create a separate table for each set of related data.
c. Identify each set of related data with a primary key.

2. Second Normal Form:
a. Meet all the requirements of the First normal form.
b. Create separate tables for sets of values that apply to multiple records.
c. Relate these tables with a foreign key.

3. Third Normal Form:
a. Meet all the requirements of the Second normal form.
b. Eliminate fields that do not depend on the key

4. Fourth Normal Form:
Fourth normal form, also called Boyce Codd Normal Form (BCNF), and fifth normal form do exist, but are rarely considered in practical design.

SQL Joins

SQL Joins

The following post gives easy explanation of types of SQL joins and its syntaces,

1. Inner Join
2. Left Join (or) Left Outer Join
3. Right Join (or) Right Outer Join
4. Self Join

1. Inner Join
Inner Join returns all the common resultset that matches the search conditions for the join

ex: SELECT e.ID, e.Name, j.salary
FROM Employee e
INNER JOIN Job j
ON e.Id = j.ID
WHERE j.Title = 'engineers'


2. Left Join or Left Outer Join:
LEFT JOIN, in a similar fashion retrives all records that match in the search condition same way and IN ADDITION with extra row for each unmatched record in the left table of the join

ex: SELECT e.ID, e.Name, j.salary
FROM Employee e
LEFT JOIN Job j (or - LEFT OUTER JOIN Job j)
ON e.Id = j.ID


3. Right Join or Right Outer Join:
RIGHT JOIN, in a similar fashion retrives all records that match in the search condition same way and IN ADDITION with extra row for each unmatched record in the right table of the join

ex: SELECT e.ID, e.Name, j.salary
FROM Employee e
RIGHT JOIN Job j (or - RIGHT OUTER JOIN Job j)
ON e.Id = j.ID


4. Self Join:
SELF JOIN is used to retrive records from the same table for a specific search condition.

The Manager column in Table Employee simply references the employee ID of another employee in the same table. And want to retrive resultset for Employee names and their Manager names, following sql query can be used,

ex:SELECT e.Name as 'EmployeeName', m.Name as 'ManagerName'
FROM employees AS e
LEFT OUTER JOIN employees AS m
ON e.manager = m.id

Thursday, November 13, 2008

Model-View-Presenter (MVP)

The MVP pattern resolves the depedency created between Model and View in MVC pattern. MVP uses a Presenter which provides a 2 way communication between the Model and View.
Execution Events:
1. Presenter passes calls from View(User Interaction) to Model, and
2. Presenter receives update events from Model, to update the View.

MVP pattern improves testability, as all the logic and processing occurs within the Presenter, but it does add some complexity to the implementation because updates must pass from the Presenter to the View.

Model-View-Controller (MVC)

The Model-View-Controller (MVC) Patterns improve reusability of business logic by separating the three components required to generate and manage a specific user interface (such as a single Web page).

Model - contains the data

View (the Web page) - will display and allow the user to manipulate
Controller - links the Model and the View, and manages all interaction and processing of the data in the Model

Execution Events:

1. User interaction with the View raises events in the Controller

2. The Model then raises events to update the View

However, this introduces a dependency between the Model and the View. To avoid this, the MVP pattern uses a Presenter that both updates the Model and receives update events from it, using these updates to update the View.

ASP.NET Patterns

Building websites has been a great attraction and fun to play with for many , though many follow some kind of coding practices without able to reason why we follow such standards in our web development.

The following post helps you to understand the basic ASP.NET patterns that can be followed for building simple - well modularised - easily maintainable Applications.

Basic Design Patterns and Groups
Design patterns fall into groups, based on the type and aims of the pattern.
For example, some patterns provide presentation logic for displaying specific views that make up the user interface. Others control the way that the application behaves as the user interacts with it.

There are also groups of patterns that specify techniques for persisting data, define best practices for data access, and indicate optimum approaches for creating instances of objects that the application uses. The following list shows some of the most common design patterns within these groups:
  • Host or Behavioral
    1. Command
    2. Publish-Subscribe / Observer
    3. Plug-in / Module / Intercepting Filter
  • Structural
    1. Service Agent / Proxy / Broker
    2. Provider / Adapter
  • Creational
    1. Factory / Builder / Injection
    2. Singleton
  • Persistence
    1. Repository