zoukankan      html  css  js  c++  java
  • Asp.NET笔记(三)--用linq实现三层架构的简单单表全查询

    用linq实现数据的简单全查询
    一、在Model层添加linq to Sql类
    二、在DAL层实现数据的全查询
    如:

       public class Comments_DAL
        {
            /// <summary>
            /// 查询所有留言信息
            /// </summary>
            /// <returns></returns>
            public List<Comments> SelectAll()
            {
                DataCommonDataContext db = new DataCommonDataContext();
    
               var result = from m in db.Comments  //这里需要引入程序集system.data.linq
                            select m;
                List<Comments> list = result.ToList();
                return list;
            }
      }

    三、在BLL层实现DAL层方法的调用
    如:

       public class Comments_BLL
        {
            //实例化DAL层的对应类
            Comments_DAL comments_DAL = new Comments_DAL();
            /// <summary>
            /// 查询所有留言信息
            /// </summary>
            /// <returns></returns>
            public List<Comments> SelectAll()
            {
                return comments_DAL.SelectAll();
            }
        }

    四、在UI层实现对BLL方法的调用和数据的展示
    如:

      在网页后台代码中

            //实例化BLL类对象
            Comments_BLL comments_BLL = new Comments_BLL();
            protected void Page_Load(object sender, EventArgs e)
            {
                //判断页面是非回发页面
                if (!Page.IsPostBack)
                {
                    List<Comments> lists = comments_BLL.SelectAll();
                    this.GridView1.DataSource = lists;
                    this.GridView1.DataBind();
                }
    
            }

     前台添加GridView1控件即可展示Comments表中的所有数据

  • 相关阅读:
    codeforces_Codeforces Round #541 (Div. 2)_abc
    小米 OJ 编程比赛 01 月常规赛_灯_找规律
    codeforces_A. Salem and Sticks_数组/暴力
    航班座位_hihocoder
    canvas
    你所必须知道的HTML
    表单及表单新增元素
    HTML5新增的结构元素
    jQuery菜单,导航与标签页
    JavaScript的DOM对象
  • 原文地址:https://www.cnblogs.com/JuneDream/p/14147783.html
Copyright © 2011-2022 走看看