zoukankan      html  css  js  c++  java
  • ADO.NET Entity Framework 一个简单数据绑定例子

    ADO.NET Entity Framework 作为 .Net Framework 3.5 SP1 的一部分发布,在VS2008Sp1中我们可以直接使用。

    下面的例子是一个非常简单GridView绑定,指在初步的了解ADO.NET Entity Framework

    我的环境配置:

    Windows Server 2008

    VSTS 2008 SP1

    SQL Server 2008

    1.建立一个Asp.Net 应用程序(C#)

    2009-03-02_130812

    2.向页面拖动一个GridView控件

    2009-03-02_131059

    3.添加一个 Ado.Net Entity Data Model文件(edmx)

    2009-03-02_131153

    4.选择从数据库生成

     2009-03-02_131215

    5.选择数据库配置,如果之前没有配置过服务器连接,可以点击右侧的“新建连接”按钮

     2009-03-02_131234

    6.选择所需表、视图、存储过程

     2009-03-02_131253

    7.点击“完成”效果如下打开了“实体框架编辑器”

    2009-03-02_131424

    通过打开模型浏览器,可以浏览模型的属性及结构

    8.向Default.aspx.cs,添加代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace ADOEF
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // 注意EDM的对象名成是数据库名称+Entities
                using (GEConfigEntities myEDMX = new GEConfigEntities())
                {
                    this.GridView1.DataSource = myEDMX.Layer;
                    this.GridView1.DataBind();  
                }
            }
        }
    }

            9.运行效果,GridView绑定了数据库中指定的表,显示所有的记录

             2009-03-02_132221

    冯瑞涛
  • 相关阅读:
    ubuntu操作技巧
    电机
    哈佛结构与冯若依曼结构
    linux command ------ ls
    Frames of Reference参考框架
    What Are Tango Poses?Tango姿态是什么?
    Google Tango Java SDK开发:Motion Tracking 运动追踪
    Google Tango Java SDK开发:Configure and Connect 配置和连接
    gradle
    Google Tango service outdated谷歌Tango的服务过时了
  • 原文地址:https://www.cnblogs.com/finehappy/p/1401444.html
Copyright © 2011-2022 走看看