zoukankan      html  css  js  c++  java
  • [原创]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());

            }


        }
    }

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

  • 相关阅读:
    堆和栈的区别
    VS-Visual Studio-IIS Express 支持局域网访问
    理解Session的几种模式
    HTTP Keep-Alive模式
    C#[Serializable]在C#中的作用-NET 中的对象序列化
    深入理解asp.net SessionState
    .NET中JSON的序列化和反序列化
    数据库相关命名规范
    PHPStorm+PHP5.6+WIN7+IIS7
    深入理解C# 静态类与非静态类、静态成员的区别
  • 原文地址:https://www.cnblogs.com/meetweb/p/1446977.html
Copyright © 2011-2022 走看看