Monday 27 March 2017

insert and bind data in gridview using 3 tier architecture in dotnet

3tier architecture example to insert and bind data in gridview
table 







Presentation(User Interface)

Source Code for above design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 {
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <div class="auto-style2">
            <strong>3Tier Example</strong></div>
        <table class="auto-style1">
            <tr>
                <td>Name</td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>City</td>
                <td>
                    <asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Email</td>
                <td>
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <asp:Button ID="btnsave" runat="server" OnClick="btnsave_Click" Text="save" />
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    
                </td>
            </tr>
        </table>
    
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </form>
</body>

</html>


DAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Class1
    {
    }
    public class ClsDataLayer
    {
        SqlConnection con = new SqlConnection("data source=ravi-PC;database='3tierexample';integrated security='true';");
        public void InsertData(string _name,String _city,String _email)
        {
            SqlDataAdapter adp = new SqlDataAdapter("insert into Usermst values('"+_name+ "','" + _city + "','" + _email + "')",con);
            DataTable dt = new DataTable();
            adp.Fill(dt);

        }
        public object SelectData()
        {
            SqlDataAdapter adp = new SqlDataAdapter("select *from Usermst", con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            return dt;
        }
    }

}

BLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using BLL;

namespace BLL
{
    
    public class Class1
    {
    }
    public class CLSBussLayer
    {
        ClsDataLayer objDAL = new ClsDataLayer();
        public void InsertUser(String _name,String _city,string _email)
        {
            objDAL.InsertData(_name, _city, _email);
        }
        public object SelectUser()
        {
            return objDAL.SelectData();
        }
    }
}

Code for Button_Click

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnsave_Click(object sender, EventArgs e)
    {
        CLSBussLayer objBLL = new CLSBussLayer();
        objBLL.InsertUser(txtname.Text, txtcity.Text, txtemail.Text);
        GridView1.DataSource = objBLL.SelectUser();
        GridView1.DataBind();
    }
}



i will give you clear explanation
follow step by step

13 comments:

  1. http://financialnew.checkseo.in/

    ReplyDelete
  2. http://www.devmanuals.com/tutorials/ms/aspdotnet/dropdownlist.html

    ReplyDelete
  3. http://www.aspdotnet-suresh.com/2014/06/best-login-page-design-in-html-css-with.html

    ReplyDelete
  4. https://github.com/puikinsh/gentelella.git

    ReplyDelete
  5. https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_well&stacked=h

    ReplyDelete
  6. for calendar hide in asp.net js code
    =======================================
    script type="text/javascript"
    function hideCalender(sender, args) {
    sender.hide();
    document.getElementById('<%= btnShow.ClientID %>').focus();
    }
    /script
    =====================
    event: OnClientDateSelectionChanged="hideCalender"

    ReplyDelete
  7. http://www.codingfusion.com/Post/Textbox-autocomplete-using-jquery-in-asp-net

    ReplyDelete
  8. http://www.c-sharpcorner.com/UploadFile/0c1bb2/create-excel-file-from-database-using-Asp-Net-C-Sharp/

    ReplyDelete
  9. http://capyei.net

    ReplyDelete
  10. http://www.c-sharpcorner.com/UploadFile/00a8b7/interview-questions-for-2-year-experience-in-sql-and-C-Sharp/

    ReplyDelete
  11. http://www.c-sharpcorner.com/UploadFile/rohatash/get-out-parameter-from-a-stored-procedure-in-Asp-Net/

    ReplyDelete
  12. http://www.devextras.com/decompiler/

    ReplyDelete
  13. https://career.guru99.com/top-22-linq-interview-questions/

    ReplyDelete