• [原创]visual 2008下使用Enterprise library4.01连接Oracle的例子


    因为项目需要,使用vs2008+Oracle开发,特意写了个例子供其他成员参考

    本例子是Oracle中的 orcl数据库

    webconfig

      <dataConfiguration defaultDatabase="ORACLE">
        <providerMappings>
          <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="System.Data.OracleClient" />
        </providerMappings>
      </dataConfiguration>
      <connectionStrings>
        <add name="ORACLE" connectionString="Data Source=orcl;Persist Security Info=True;User ID=scott;Password=scott;Unicode=True"
          providerName="System.Data.OracleClient" />
      </connectionStrings>
      <appSettings />

    自己建立的一个公共连接类,大家可以拓展

    EDataCommon.cs

     using System.Data.Common;
    using Microsoft.Practices.EnterpriseLibrary.Data; 

    public DataSet getDataSet(string sql)
        {
            DataSet ds = null;
            try
            {
                db = DatabaseFactory.CreateDatabase();
                ds = db.ExecuteDataSet(CommandType.Text, sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;
        }

    页面后台程序,

    Index.aspx.cs

    public partial class connect : System.Web.UI.Page
    {
      

        protected void Page_Load(object sender, EventArgs e)
        {
          
            try
            {
                this.GridView1.DataSource = new EDataCommon().getDataSet("select * from dept;").Tables[0];
                this.GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());

            }


        }
    }

    如果大家有任何疑问请及时联系.. :-) 其实够简单的啦

  • 相关阅读:
    having——至少被订购过两回的订单
    产品——仓库表查询
    SQL 聚集函数使用
    select count(*)和select count(1)的区别 (转)
    SpringAOP 通知(advice)
    Spring AOP 实现原理与 CGLIB 应用
    cglib 动态代理基础篇
    模仿Struts2的Interceptor拦截器实现
    利用JDK动态代理机制实现简单拦截器
    java多线程总结二:后台线程(守护线程)
  • 原文地址:https://www.cnblogs.com/meetweb/p/1446977.html
Copyright © 2020-2023  润新知