First, refer to the Oracle namespace
System.Data.OracleClient;
Second, connect the database code:
Private DataTable SqlHelper (string commadtext) { try { //through configuration file, connection database //string connectionstr = configurationsettings.appsettings["ConnectionString"]. ToString (); OracleConnection conn = new OracleConnection (CONNECTIONSTR); Direct string Connection Database OracleConnection conn = new OracleConnection ("Data source=192.168.1.3; User id=epv7; PASSWORD=EPV7; Max Pool Size = + "); Conn. Open (); OracleDataAdapter SqlDA = new OracleDataAdapter (COMMADTEXT, conn); DataSet ds = new DataSet (); Sqlda.fill (DS); Conn. Close (); Return DS. Tables[0]; } catch (Exception ex) { throw ex; } }
Third, through the configuration file connection database, configuration file content:
<configuration> <appSettings> <!--<add key= "DBType" value= "SQ"/>--> <!-- <add key= "ConnectionString" value= "server=.;D Atabase=winstudent;uid=test;pwd=test "/>--> <add key=" ConnectionString "value=" Data source= 192.168.1.113; User id=epv7; PASSWORD=EPV7; Max Pool Size = "/> </appSettings></configuration>
If the following error occurs:
BadImageFormatException is raised when attempting to load the Oracle client library. This issue occurs if you are running in 64-bit mode with the 32-bit Oracle client component installed
Solution One:
Click the solution you want to run--right----properties, select Build---target platform, and change to x86
Solution Two:
Download the following DLL file and add a reference
Devart.data
Devart.Data.Oracle
The reference namespace is:
Using Devart.Data.Oracle;
Oracle Connection Database