(三层架构入门)最基本的三层架构搭建方法(详细过程及所有代码)

一、打开 Microsoft Visual Studio 2010软件

二、新建一个C#空网站

三、选中项目名(jinlanyan),右键----》添加新项(index.aspx)

四、添加App_Code文件夹,右键项目名(jinlanyan)---》添加asp.net文件夹---》App_Code


五、在App_Code中添加三个普通的文件夹,右键App_Code,选择新建文件夹

六、右键BLL,选择添加新项,依次添加三个类(SubjectBLL.cs、SubjectDAL.cs和SubjectModel.cs),其中SqlHelper.cs为数据库访问类,代码后面给出。



附逻辑说明:index页面调用bll,bll再调用dal,再按顺序返回结果。

七、数据表见下图



八、运行截图


九、各页面代码

index.aspx页面代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="margin: auto;background-color:#33ccff">
            <tr>
                <td>
                    按新闻 newsId 查询:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="查询" οnclick="Button1_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:GridView ID="GridView1" runat="server" Style="margin: auto" OnRowDeleting="Subject_RowDeleting1"
                        OnRowEditing="Subject_RowEditing" OnRowUpdating="Subject_RowUpdating" 
                        onrowcancelingedit="GridView1_RowCancelingEdit">
 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值