• Enterprise Library 3.1 简化使用范例一


    笔者认为Enterprise Library 3.1 - May 2007提供的功能过于强大,可能项目里很多不需要.所以想简化使用

    步骤一. 安装Enterprise Library 3.1 - May 2007

    步骤二.建立你的项目.建立bin目录.引入Microsoft.Practices.EnterpriseLibrary.Data.dll

    Microsoft.Practices.EnterpriseLibrary.Common.dll

    步骤三.在web.config文件里建立一项

    <connectionStrings>
        <add name="myconn" connectionString="Data Source=SEE-CLN-059\PMSERVER;Initial Catalog=test;User ID=sa;Password="
          providerName="System.Data.SqlClient" />
      </connectionStrings>

    下面只展示如何读出数据的例子.其他跟你自己写类差不多效果啦

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

    <!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>
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
       
        </div>
        </form>
    </body>
    </html>

    codebehide

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Microsoft.Practices.EnterpriseLibrary.Data;

    public partial class enterprisetest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Database db = null;
            try
            {

                string strconn = "myconn";
                db = DatabaseFactory.CreateDatabase(strconn);
                DataSet ds = db.ExecuteDataSet(CommandType.Text, "select   Class_ID,Class_Name,Class_Pid   from   TC_Class   order   by   Class_ID ");
                this.GridView1.DataSource = ds.Tables[0];
                this.GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());

            }

           
        }
    }

     

    漏了一点提示.必须建立连接字符串在web.config里,否则会抛出异常.. :-)

     


  • 相关阅读:
    Linux平台不同解压缩命令的使用方法
    poj 1274 The Perfact Stall
    Experience Design for Sexable Forum
    JavaScript中的Array对象方法调用
    iOS9适配小结
    [Servlet&amp;JSP] HttpSession会话管理
    Android中的跨进程通信方法实例及特点分析(一):AIDL Service
    OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)
    《Effective Modern C++》翻译--条款4:了解怎样查看推导出的类型
    Android开发系列之ListView
  • 原文地址:https://www.cnblogs.com/meetweb/p/1248767.html
Copyright © 2020-2023  润新知