-->

Tuesday, March 8, 2016

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#

Sunday, March 6, 2016

GridView BoundField Example in ASP.NET C#

In this article i will show you, How to use BoundField of GridView in ASP.NET C#. Actually, BoundField is the Default field of GridView Control, used for DataBinding purpose. In my previous article i have already use this field with SQL DataSource control. Check mentioned below link:

[Video Contain BoundField + SQLDataSource + ADO.NET]


Now, Learn, How to create BoundField manually also bind them using ADO.NET Technology with Database table. First to create a database table, insert some data into table. Prepare BoundField like this:

  <asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
        <Columns>

            <asp:BoundField DataField="Id" HeaderText="Identification No" />
            <asp:BoundField DataField="Name" HeaderText="Name of User" />

        </Columns>
   </asp:GridView>

Code Behind Code:

using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;

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

    private void bindGrid()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        con.Open();
        SqlCommand cmd= new SqlCommand();
        cmd.CommandText = "select * From [usertable]";
        cmd.Connection =con;
        SqlDataReader rd= cmd.ExecuteReader();
        g1.DataSource =rd;
        g1.DataBind();
    }
}

Code Generates the following output:

GridView BoundField Example in ASP.NET C#

How to retrieve records from database table in MVC

In this article i will show you, How to retrieve record from database table in MVC. This things we have already learned in ASP.NET WEB FORMS, Now the same things we can do in MVC. Before doing this task first to install Entity Framework in the application. Create a Empty MVC project. Add a new database also create table by using this video tutorial. We have a database table with their following fields:

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

Now, Following these steps to retrieve items from table:

Step-1 :  Create a "Student" model class in model folder. Like :

using System.ComponentModel.DataAnnotations.Schema;

namespace WebApplication19.Models
{
    [Table("Student_Table")]
    public class Student
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string City { get; set; }
    }
}

By using the Table class we can mapped our class to database table. 

Step-2 : Create a "StudentContext" class in model folder. Like

using System.Data.Entity;

namespace WebApplication19.Models
{
    public class StudentContext : DbContext
    {
        public DbSet<Student> students { get; set; }
    }
}

By using "students" property we can communicate with the table.

Step-3 : Create ConnectionString in the Web.Config file, in this way :

<connectionStrings>

    <add name="StudentContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
 
here we have a connection name is same as Context Class name.

Step-4 : Now, add a controller in the Controller folder, copy this code under controller action method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication19.Models;

namespace WebApplication19.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            StudentContext sc = new StudentContext();
            Student singlestu = sc.students.Single(stu => stu.Id == 2);
            return View(singlestu);
        }
    }
}

By using the LINQ Query we have to retrieving student details from table who's id is 2. Now, Build the project. Add a View By Right click on Index Action method.Now, appear a screen look like this.

How to retrieve records from database table in MVC

Fill all mentioned fields, according to mentioned snaps. Now, last
Step-5 : Design to view for values.

@model WebApplication19.Models.Student

@{
    ViewBag.Title = "Student";
}

<h2>Single Student Record</h2>
<div>
    Student Id : @Model.Id <br/>
    Student Name : @Model.Name <br/>
    Student City : @Model.City

</div>

Code Generates the following output:
How to retrieve records from database table in MVC


Friday, March 4, 2016

How to install Entity Framework from console and Solutions in MVC

By using the Entity Framework you can can communicate with the Sql Server.  In which we have two approaches i.e "Code First" and "Model First". But, In this article, I will explain you how to install Entity Framework from console and Solutions:
Install From Console:
1. Select "Package Manager Console" by the following path :
 Tools -> NuGet Package Manager--> Package Manager Console

Note : Before type the command in command line, must to ensure your internet connection.

Type command in Command Line:

PM> Install-Package EntityFramework


Install From Solution: 
1. Select "Manage Nuget Packages for Solutions... " by the following path :
 Tools -> NuGet Package Manager--> Manage Nuget Packages for Solutions...

Note : Before type the command in command line, must to ensure your internet connection.
Search Entity Framework in search bar, which reside in right side bar.

Manage Nuget Packages for Solutions...

Thursday, March 3, 2016

Edit Update GridView Row using Command Name

In this article, I will show you how to update GridView row. By using edit button we can update GridView row. But the question is, how to design "Edit" button for delete. If you follow me then i am sure you can delete rows from GridView.
Mentioned Following steps are:
Step-1 : Add a GridView Control on source window by using html code. Now, in the source page you have.
<asp:GridView ID="g1" runat="server">
</asp:GridView>

Step-2: Add these mentioned properties in the GridView:
AutoGenerateColumns="false"
 OnRowCancelingEdit="g1_RowCancelingEdit"
 OnRowEditing="g1_RowEditing"
 OnRowUpdating="g1_RowUpdating"

 Here, we have AutoGenerateColumns="false" means you design GridView columns manually. OnRowCancelingEdit is a event through this you can cancel the process of editing. OnRowEditing is also a event through this you can edit new Index. By using OnRowUpdating event you can update rows with new Data. 

 Step-3 : Suppose we have two fields in Database table then you can design GridView for this way. Now, the complete code of GridView is:

Source Code:


  <asp:GridView ID="g1" runat="server" AutoGenerateColumns="false" OnRowCancelingEdit="g1_RowCancelingEdit" OnRowEditing="g1_RowEditing" OnRowUpdating="g1_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="Controls">
                    <ItemTemplate>
                        <asp:Button Text="Edit" ID="Editbutton" runat="server" CommandName="Edit" />
                    </ItemTemplate>
                    <EditItemTemplate>
                         <asp:Button Text="Update" ID="updatebutton" runat="server" CommandName="Update" />
                         <asp:Button Text="Cancel" ID="cancelButton" runat="server" CommandName="Cancel" />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Id">
                    <ItemTemplate>
                        <asp:Label ID="idlbl" runat="server" Text='<%# Eval("Id") %>' />
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label ID="namelbl" runat="server" Text='<%# Eval("Name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="nametext" runat="server" Text ='<%# Eval("Name") %>' />
                    </EditItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>    

In the First Template field we have two templates i.e ItemTemplate and EditItemTemplate. By using ItemTemplate we can show Edit Button with their "Edit" Command Name Property. When you click on it then open EditItemTemplate, in which we have two buttons in same column i.e Update and Cancel. similarly Design two columns for data. Pick the data from the database table using Embedded code block. 

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 Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bindgrid();
        }

    }

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

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

        SqlDataReader rd = cmd.ExecuteReader();
        g1.DataSource = rd;
        g1.DataBind();
        con.Close();
    }
    protected void g1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        g1.EditIndex = e.NewEditIndex;
        bindgrid();
    }
    protected void g1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        g1.EditIndex = -1;
        bindgrid();
    }
    protected void g1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label l1 = g1.Rows[e.RowIndex].FindControl("idlbl") as Label;
        TextBox t1 = g1.Rows[e.RowIndex].FindControl("nametext") as TextBox;
        SqlConnection con = new SqlConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        con.Open();

        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "update [usertable] set Name=@nm where Id=@id1";
        cmd.Parameters.AddWithValue("@id1", l1.Text);

        cmd.Parameters.AddWithValue("@nm", t1.Text);
        cmd.Connection = con;
        cmd.ExecuteNonQuery();

        g1.EditIndex = -1;
        bindgrid();



    }
}

Code Generates the following output

Edit Update GridView Row using Command Name

Edit Update GridView Row using Command Name

Sunday, February 28, 2016

How to design finger print/ scanner based project in C#

In this article, I will show you, how to compare two images in c#. You can say that how to match prints images in c#. Basically, this types things we can implement in biometric systems like fingerprint etc. If you want to work on this system, follow these mentioned steps to complete this task.


Step-1:  Create a windows form project using Visual Studio, you can take any version of visual studio.

Step-2:  Design output type form in default added file ie. form1

Step-3:  Copy and Paste mentioned code, according to their controls

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Fingure_print
{
    public partial class Form2 : Form
    {
        Bitmap bitmapPictureBox1;
        Bitmap bitmapPictureBox2;
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                pictureBox1.ImageLocation = openFileDialog1.FileName;

                bitmapPictureBox1 = new Bitmap(openFileDialog1.FileName);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                pictureBox2.ImageLocation = openFileDialog1.FileName;

                bitmapPictureBox2 = new Bitmap(openFileDialog1.FileName);
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool compare = ImageCompareString(bitmapPictureBox1,bitmapPictureBox2);
            if(compare==true)
            {
                MessageBox.Show("match");

            }
            else
            {
                MessageBox.Show("not");
            }
        }
        public static bool ImageCompareString(Bitmap firstImage, Bitmap secondImage)
    {
       MemoryStream ms = new MemoryStream();
        firstImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        String firstBitmap = Convert.ToBase64String(ms.ToArray());
       ms.Position = 0;
   
       secondImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        String secondBitmap = Convert.ToBase64String(ms.ToArray());
 
      if (firstBitmap.Equals(secondBitmap))
      {
         return true;
     }
       else
       {
          return false;
     }
   }
    }
}

Code Generates the following output
How to design finger print/ scanner based project in C#





Saturday, February 27, 2016

Blood bank System project in ASP.NET C#

Introduction
The blood bank system provides some information about blood bank. A needy person can take some points of blood with their blood groups. By using this system, we provides the information  about donor and takers. These all information are public. Any one  person register in the control panel and after successfully register in the panel. He/She can login in the system. We have a form for donor, in this form, donor fill these mentioned fields.

Donor Id :  Int type
Name :  nvarchar (100)
Blood Group :  nvarchar ( 50)
Contact ( Phone Number)  : nvarchar (50)
Address : nvarchar(max)
Picture:  nvarchar(max)

Blood bank System project in ASP.NET C#


After filling the form, information display on home screen, registered user can see donor information. Project also provide the search facility, through it, registered user can see donor information, according to blood group. It provide the total storage of blood in the bank. Bank takes blood from outer side also vice versa. Total in and out details stored in separate database table.

Software information : Visual Studio 2013
Hardware requirement :  Visual Studio 2013 compatible hardware.

Video : Comming Soon

How to run it: You can run it using video help.

Download/Buy : mail me narenkumar851@gmail.com




© Copyright 2013 Computer Programming | All Right Reserved