Oracle[原创]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());

        }

    }
}

若果大家有其余疑问请及时联系.. 🙂 其实够简单的啊

相关文章