How to Create Registration Form in ASP.NET with MySQL

Hello Developers, Here is Article to Create Simple Registration Form in C# ASP.NET using MySQL.Here i am using Microsoft Visual Studio and MySQL.Let’s Follow some important steps.

step 1 :Open Visual Studio.Go to File Tab –>Project –>Web –>ASP.NET Web Application –>Select Empty –>Check Web Forms and MVC–>OK. See below image.

step 2: Right click on Project –>Add –>Web Forms –>Item name –> OK. see below image.

Step 3: Remove all previous Codes and Copy+Paste Following given codes.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="LoginTest.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            font-size: xx-large;
            color: #003399;
        }
        .auto-style3 {
            width: 401px;
        }
        .auto-style4 {
            background-color: #0099CC;
        }
        .auto-style5 {
            background-color: #33CCCC;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table class="auto-style1">
                <tr>
                    <td>
                        <table class="auto-style1">
                            <tr>
                                <td class="auto-style2"><strong>-------------------Register---------------</strong></td>
                            </tr>
                            <tr>
                                <td>Create Your Account.Its Free and Only Takes a Minute</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <table class="auto-style1">
            <tr>
                <td class="auto-style3">
                    <asp:Label ID="Label1" runat="server" Text="Enter First Nae"></asp:Label>
                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtFirstName" ErrorMessage="Enter FirstName" ForeColor="#FF3399"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="Enter Last Name"></asp:Label>
                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLastName" ErrorMessage="Enter Last Name" ForeColor="#FF3399"></asp:RequiredFieldValidator>
                </td>
            </tr>
        </table>
        <table class="auto-style1">
            <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="Enter Email"></asp:Label>
                    <asp:TextBox ID="txtEmail" runat="server" TextMode="Email" Width="348px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEmail" ErrorMessage="Enter Email" ForeColor="#FF3399"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="Enter Password"></asp:Label>
                    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="316px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPassword" ErrorMessage="Enter Password" ForeColor="#FF3399"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label5" runat="server" Text="Enter Confirm Password"></asp:Label>
                    <asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" Width="258px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtConfirmPassword" ErrorMessage="Enter Confirm Password" ForeColor="#FF3399"></asp:RequiredFieldValidator>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPassword" ControlToValidate="txtConfirmPassword" ErrorMessage="Password Must be Match" ForeColor="#FF3399"></asp:CompareValidator>
                </td>
            </tr>
        </table>
        <asp:CheckBox ID="CheckBox1" runat="server" CssClass="auto-style5" Text="I accept the Terms of Use &amp; Privacy Policy" />
        <table class="auto-style1">
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" CssClass="auto-style4" Height="50px" OnClick="Button1_Click1" Text="Submit" Width="306px" />
                    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

Step 4. Install two important packages “mysql-for-visualstudio” and “mysql-connector”. see below image.Click “Tools” Tab and next Click “Connect to Database”. Choose “MySQL Database” from Data source and click “Continue” button. see below image.

Step 5.Give MySQL Server name ,Enter User name and Password. Select or enter a database(sakila) from drop-down box. Click “Test Connection” button. if connection succeeded then click OK. Follow below image.

Step 6 .Right click on References–>Add References–>Browse–>give the path–>select “MySql.Data.dll” –>click “Add” button. see below image.

Step 7.Add package “using MySql.Data.MySqlClient. After write any types of codes related with MySQL. see below image.

Output Screen , See below image.

Happy Coding…Thanks..

Post Author: adama