[原创]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());
}
}
}
如果大家有任何疑问请及时联系.. :-) 其实够简单的啦