Address Book Tutorial in C#.Net using SQL Server Database

In this tutorial I am using C#.net programming language to demonstrate basic address book. The address book is full application and can be used to store real data. You can learn various aspect of c# programming like, SQL connection, CRUD operation ( Create, Read, Update and Delete ). Printing in C#.Net, PrintPreview.

Let's start the step by step tutorial for creation this full application in c#.net programming language. The same application can be converted easily to VB.net programming language.

At first let us design our database in sql server management studio.

Run sqlserver management studio and create a new database named addressbook.

CREATE database addressbook;

The database is created now. now use it typing the following code:

USE addressbook;

Now , let us create various field which is required for our telephone diary or address book.

Name Data Type
Id int
Name nvarchar(50)
Address nvarchar(255)
Phone nvarchar(50)

open new query window and fire the following sql query to create required table and field.

CREATE TABLE Address

(

ID int IDENTITY(1,1) PRIMARY KEY,

Name nvarchar(50),

Address nvarchar(255),

Phone nvarchar(50)

)

Screenshot of database creation.

create database using sql server management studio

Here, we have created a new table with name Address, the table contains ID, Name for storing full name , Address to store detail address so the nvarchar length is 255 character , similarly Phone with 50 character.

We have used nvarchar instead of varchar as we want to store unicode nepali character.

Now let us launch Microsoft Visual Studio and create a new Windows Forms Application giving a meaningful name , I am giving AddressBook, I am using 2012 version for this tutorial.

Let create a new class named Log, right click the project and add new class, we use this log class to save any error or log generated by our software,

write the following code in the log class, the full class is as follows:

using System;
using System.IO;
using System.Windows.Forms;

namespace AddressBook
{
    class Log
    {

       static bool saveLog = true;
       static string logFile = Application.StartupPath + "\\log.txt";

       private Log()
       { 
       
       }

        public static void Save(string Msg)
        {

            if (saveLog)
            {
                try
                {
                    string data = DateTime.Now.ToString() + ":" + Msg + Environment.NewLine;
                    File.AppendAllText(logFile, data);
                }
                catch
                { 
                
                }

            }
        
        }
    }
}

We have only one method here named 'Save' , this method is used to save any error or information the filename called log.txt in the application folder. The method is static so that we don't have to instantiate a new class. We can simply call Log.Save("log message"); directly to save any log data.

Now let us design our address book adding form, i am modifying default Form1.

c#.net tutorial address book design

Name Component Type Text
lbltitle Label control Easy Phone Diary
lblname Label control Name:

 

lblphone Label control Phone:

 

lbladdress Label control Address:

 

txtName TextBox  
txtPhone TextBox  
txtAddress TextBox ( Multiline )

 

 
lblstatus Label control  
btnSave Button Save
btnCancel Button Exit

In our next C#.Net Address Book Tutorial we will add code on save button.

If you find any error or want to suggest author please contact us via our contact page.