zoukankan      html  css  js  c++  java
  • 使用表格显示数据库中的数据

    Displaying a Table of Database Data

    The goal of this tutorial is to explain how you can display an HTML table of database data in an ASP.NET MVC application. First, you learn how to use the scaffolding tools included in Visual Studio to generate a view that displays a set of records automatically. Next, you learn how to use a partial as a template when formatting database records.

      这篇教程的目的是讲解如何在ASP.NET MVC应用程序中使用HTML表格显示数据库中数据。首先,你将学会如何使用Visual Studio自带的支架工具自动生成一个View来显示一个记录集。接下来,你将学习如何使用一个局部页面模板格式化显示数据库的记录。

    Create the Model Classes

    We are going to display the set of records from the Movies database table. The Movies database table contains the following columns:

      我们将要做的是显示Movies 数据表中的记录集,Movies 数据表包含了以下的列:

    Column Name Data Type Allow Nulls
    Id Int False
    Title Nvarchar(200) False
    Director NVarchar(50) False
    DateReleased DateTime False

    In order to represent the Movies table in our ASP.NET MVC application, we need to create a model class. In this tutorial, we use the Microsoft Entity Framework to create our model classes.

    In this tutorial, we use the Microsoft Entity Framework. However, it is important to understand that you can use a variety of different technologies to interact with a database from an ASP.NET MVC application including LINQ to SQL, NHibernate, or ADO.NET.

      为了在 ASP.NET MVC应用程序中表示Movies表,我们需要创建一个模型类,在这篇教程,我们使用 Microsoft Entity Framework 来创建我们的模型类。

      在这篇教程,我们使用 Microsoft Entity Framework 。然而,重要的是你要理解在ASP.NET MVC应用程序中你可以使用不同的技术包括LINQ to SQL, NHibernate, 或者ADO.NET来与数据库进行交互。

    Follow these steps to launch the Entity Data Model Wizard:

    1. Right-click the Models folder in the Solution Explorer window and the select the menu option Add, New Item.
    2. Select the Data category and select the ADO.NET Entity Data Model template.
    3. Give your data model the name MoviesDBModel.edmx and click the Add button.

    请按照以下的步骤来启动实体数据模型向导:

    1. 在解决方案资源管理器窗口中,右键单击Models文件夹,选择菜单“添加”,“添加新项”。
    2. 选择类别数据,然后选择ADO.NET Entity Data Model 模板。
    3. 给你的数据模型命名为MoviesDBModel.edmx ,然后点击添加按钮。

    After you click the Add button, the Entity Data Model Wizard appears (see Figure 1). Follow these steps to complete the wizard:

    1. In the Choose Model Contents step, select the Generate from database option.
    2. In the Choose Your Data Connection step, use the MoviesDB.mdf data connection and the name MoviesDBEntities for the connection settings. Click the Next button.
    3. In the Choose Your Database Objects step, expand the Tables node, select the Movies table. Enter the namespace Models and click the Finish button.

    当你点击添加按钮后,实体数据模型向导将会出现,按照这些步骤来完成该向导:

    1. 在选择模型内容这一步,选择从数据库中生成选项。
    2. 在选择您的数据连接这一步,使用MoviesDB.mdf 数据连接,然后给数据连接配置命名为MoviesDBEntities
    3. 在选择数据库对象这一步,展开表节点,选择Movies表,输入模型的命名空间,点击完成按钮。

    Figure 01: Creating LINQ to SQL classes (Click to view full-size image)

  • 相关阅读:
    (转)bash内置命令mapfile:读取文件内容到数组
    new 一个接口?
    Linq的一些操作符图表展示
    StreamReader 和文件乱码
    XSLT 的调试
    不一样的大小写转换
    一些可能没用过的调试窗口
    私人工具分享:博客下载工具
    简单的实例来理解WCF 数据服务
    谈谈char ,nchar,varchar,nvarchar 和Uniqueidentifier
  • 原文地址:https://www.cnblogs.com/supperwu/p/1625045.html
Copyright © 2011-2022 走看看