Oralce版本:11g R2
1、将oci.dll、ociw32.dll、Oracle.DataAccess.dll、orannzsbb11.dll、oraocci11.dll、oraociicus11.dll、OraOps11w.dll拷到bin目录下
2、添加对Oracle.DataAccess.dll的引用
3、编写代码,如:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Oracle.DataAccess.Client;
- namespace Oracle1
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- string connstring = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.37)(PORT=1521))" +"(CONNECT_DATA=(SID=orcl)));User Id=system;Password=ikmbikmb;";
- using (OracleConnection conn = new OracleConnection(connstring))
- {
- conn.Open();
- string sql = "select * from t1 t";
- using (OracleCommand comm = new OracleCommand(sql, conn))
- {
- using (OracleDataReader rdr = comm.ExecuteReader())
- {
- while (rdr.Read())
- {
- Response.Write(rdr.GetString(1) + "<br>");
- }
- }
- }
- }
- }
- }
- }