-->

Tuesday, March 29, 2016

How to use ADO.NET Entity Data model with database

ADO.NET Entity Data Model provides you a better and fast approach for communicating with database objects like Table, Stored Procedure etc. After added it, you have some models (classes ) which is related to tables and context classes. I mean to say that you can access database table directly by using context classes. In the context class, we have some public properties, through these we can retrieve table values. These all such things are related to model first approach , i mean to day that ADO.NET Entity Data model is based on model first approach. Let's start to configure it with the database, you can follow these steps , if you want to configure it:
Step-1 : Right Click on your project name , select add new item from the appearing menu. 
Step-2 :
How to use ADO.NET Entity Data model with database
 
Step-3: Press "OK" to continue.
Step-4: Select "EF designer from Database" option in the Entity Data Model wizard.
Step-5:  Now, press Next to continue in model wizard, select Connection string from Dropdown menu if exists. You can create "New Connection" by using Sql Server Database.

Entity Data Model Wizard

Step-6: Also select "Save Connection String into web.config file" CheckBox to save your whole connection parameter in web.config file.
Step-7: Press "Next" to continue. Select either all of them  Table, Views, Stored processor and one of them.
How to use ADO.NET Entity Data model with database

Step-8: Click to "Finish" Button.

Thursday, March 24, 2016

DropdownList Selected Disabled Default item in ASP.NET C#

In this article, I will show you, How to add default item at index 0 in DropdownList, also select default item, default item will be disabled when drop down the popup. For this task, first of all bind the DropdownList then you can add default item at index first by using following line of code:

      DropDownList1.Items.Insert(0, "Select");
After that you can select or disabled default item by the following line of code:
        DropDownList1.Items[0].Selected = true;
        DropDownList1.Items[0].Attributes["Disabled"] = "Disabled";
Source Code

<div>
    
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    
    </div>

Code Behind Code

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default9 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            binddrop();
        }
    }

    private void binddrop()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString  =ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        con.Open();

        SqlCommand cmd = new SqlCommand();
        cmd.CommandText ="select * from [Employee]";
        cmd.Connection =con;

        SqlDataReader rd=  cmd.ExecuteReader();
        DropDownList1.DataSource =rd;
        DropDownList1.DataTextField = "Name";
        DropDownList1.DataValueField = "Id";
        DropDownList1.DataBind();

        DropDownList1.Items.Insert(0, "Select");
        DropDownList1.Items[0].Selected = true;
        DropDownList1.Items[0].Attributes["Disabled"] = "Disabled";


    }
}

Code generates the following output :


Monday, March 21, 2016

Online Course Registration System Project in ASP.NET C#

In this Project we have a logical system. By using this system we can store courses and their subjects in the system database. The all things we can do by administrator. First of all, administrator do login in the system. He/ She can change our profile like change password, username and etc. In the Courses tab, we will provide some following things like "Manage Courses", "Add Courses", "Manage subject combination" and "Add subject combination". In the section of Manage courses, i will provide you a GridView control with the following action control like:

Manage Courses

By using Edit and Delete button we can make some changes in the course table. By using Subject combination we can configure subjects under defined courses. I will provide you a interface through which you can add new courses in the table like :

After add course details , you can add subjects in particular course also configure it by using some action command like "Edit" and "Delete". Now, by mentioned snap, you can add new subject details in the courses like:
subject details in the courses

Software Requirement :  Visual Studio 2013

Download : mail me : narenkumar851@gmail.com

Saturday, March 19, 2016

Online Hotel Reservation Project in ASP.NET C#

Introduction

Through this project we are booking a hotel room in a city also reduce lots of paper work. Actually physical process converted into logical process or you can say online process.

In this project we will provide such types of  searching functionality:

  • Pick random city 
  • Search city
  • You can search hotel directly
home page of hotel reservation system in asp.net c#

Module of the project :
  • Visitor 
  • Administrator 
Full detail of hotel address

Working of the project

First of all visitor choose the hotel city by the help of searching facilities. In the search result we will provide some basic information about each hotel which is exist in the city. When visitor select a specific hotel in the given list, we will provide the full details of selected hotel with "book now" button. When visitor press this button, the system will check that visitor is whether authenticated or not. If visitor is not authenticated then visitor moves to the login page. Login page contain a link of register page. If visitor not a website user then she/he will not login by the login panel so first of all visitor should member of the website. After that he /she will booked the selected hotel.

Download :  narenkumar851@gmail.com

Wednesday, March 9, 2016

Bind TreeView with Country state and city | multiple table in ASP.NET C#

In this article i will show you how to bind TreeView at 2 level, you can say that Bind tree view with country , state and city table. Country table data bind at 0 level , state data bind at 1 level and last city data bind at 2 level. So first of all create three table, Sql Script mentioned below:


Database Table : (Country)

CREATE TABLE [dbo].[Country] (
    [Id]   INT           IDENTITY (1, 1) NOT NULL,
    [Name] NVARCHAR (50) NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

Database Table : (State)

CREATE TABLE [dbo].[state] (
    [Id]   INT           NOT NULL,
    [Name] NVARCHAR (50) NULL,
    [cid]  INT           NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

Database Table : (City)

CREATE TABLE [dbo].[city] (
    [Id]   INT           NOT NULL,
    [Name] NVARCHAR (50) NULL,
    [sid]  INT           NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

Now, add the tree view in web form. Now, your source page looking like this.

Source Code :

<asp:TreeView ID="TreeView1" runat="server">
        </asp:TreeView>


Code Behind Code :

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default6 : System.Web.UI.Page
{
    static int count = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = this.GetData("SELECT Id, Name FROM [Country]");
            this.PopulateTreeView(dt, count, null);
        }
    }
    private void PopulateTreeView(DataTable dtParent, int parentId, TreeNode treeNode)
    {
        foreach (DataRow row in dtParent.Rows)
        {
            TreeNode child = new TreeNode
            {
                Text = row["Name"].ToString(),
                Value = row["Id"].ToString()
            };
            if (parentId == 0)
            {
                TreeView1.Nodes.Add(child);
                DataTable dtChild = this.GetData("SELECT Id, Name FROM [state] WHERE cid = " + child.Value);
                count =1;
                PopulateTreeView(dtChild,count , child);
            }
            else if (parentId == 1)
            {
                treeNode.ChildNodes.Add(child);
                DataTable dtChild = this.GetData("SELECT Id, Name FROM [city] WHERE sid = " + child.Value);
                count =2;
                PopulateTreeView(dtChild,count, child);
            }
            else
            {
                treeNode.ChildNodes.Add(child);

            }
         
        }
    }

    private DataTable GetData(string query)
    {
        DataTable dt = new DataTable();
        string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand(query))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    sda.Fill(dt);
                }
            }
            return dt;
        }
    }
}

In this code First to bind DataTable with the Country table, for each country , retrieved State name and for each state name , retrieved city name. Here, we have recursion technique. In the Populate TreeView method parent id define the level of the tree view.

Now, Code Generates the following output:
Bind TreeView with Country state and city | multiple table in ASP.NET C#


Tuesday, March 8, 2016

Default Membership Provider must be specified

Create User Wizard control is used to store information of the user or visitor into the database table. ASP.net provide the control through this we can store limited information of the client into the database table. But we can change its user interface. You can say customization of Grid View. When we drag it on design window then its look like:

Customization of CreateUserWizard Control

Select Create User Step link by using "show smart tag". After that you can make some changes in fields. Like if You want to remove "Security Answer" and Security Question. Suppose you have to remove it then your interface look like:

 remove "Security Answer" and Security Question.

But when you run it then you get error like :

Default Membership Provider must be specified.

[Solution]
Add tags in web. config file.
<system.web>
<membership>
      <providers>       
        <clear />
      <add requiresQuestionAndAnswer="false" name="AspNetSqlmembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" applicationName="Application"/>
      </providers>
    </membership>
</system.web>
Code Generates the following output
Customization of CreateUserWizard Control in ASP.NET C#

Customization of CreateUserWizard Control in ASP.NET C#

Create User Wizard control is used to store information of the user or visitor into the database table. ASP.net provide the control through this we can store limited information of the client into the database table. But we can change its user interface. You can say customization of Grid View. When we drag it on design window then its look like:


Customization of CreateUserWizard Control

Select Create User Step link by using "show smart tag". After that you can make some changes in fields. Like if You want to remove "Security Answer" and Security Question. Suppose you have to remove it then your interface look like:

 remove "Security Answer" and Security Question.

But when you run it then you get error like :

Default Membership Provider must be specified.

[Solution]
Add tags in web. config file.
<system.web>
<membership>
      <providers>       
        <clear />
      <add requiresQuestionAndAnswer="false" name="AspNetSqlmembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" applicationName="Application"/>
      </providers>
    </membership>
</system.web>
Code Generates the following output
Customization of CreateUserWizard Control in ASP.NET C#

© Copyright 2013 Computer Programming | All Right Reserved