You want to access the Oracle database in C #, after all, it is development and you want lightweight access to Oracle, and you can run the program without having to install an Oracle environment on the client.
Find the relevant information on the Internet, only need to reference a DLL can be implemented.
Access code (reference DLL required):
Public classOracleconfig {//string connstring = "Data source= (description= (address= (protocol=tcp) (HOST=IP) (port=1521)) (Connect_data= ( (SERVICE_NAME=ORCL))); Persist Security info=true; User Id=system; Password=password; "; Public stringHost {Get;Set; } Public stringPort {Get;Set; } Public stringService {Get;Set; } Public stringID {Get;Set; } Public stringPassword {Get;Set; } }
Public classOraclehelper {oracleconfig oracleconfig; OracleConnection OracleConnection; OracleDataReader OracleDataReader; OracleCommand OracleCommand; PublicOraclehelper (Oracleconfig oracleconfig) { This. Oracleconfig =Oracleconfig; } PublicOracleDataReader Getdatareader (stringCommandText) {getoracleconnection (oracleconfig); OracleCommand=Oracleconnection.createcommand (); Oraclecommand.commandtext=CommandText; OracleDataReader=OracleCommand.ExecuteReader (); returnOracleDataReader; } Public voidCloseConnection () {oracledatareader.close (); Oracledatareader.dispose (); Oraclecommand.dispose (); Oracleconnection.close (); Oracleconnection.dispose (); } Private voidgetoracleconnection (Oracleconfig oracleconfig) {OracleConnection=NewOracleConnection (); Oracleconnection.connectionstring=string. Format ("Data source= (description= (address= (protocol=tcp) (host={0) (Port={1})) (Connect_data= (service_name={2})); Persist Security info=true; User id={3}; PASSWORD={4};", Oracleconfig.host,oracleconfig.port,oracleconfig.service,oracleconfig.id,oracleconfig.password); Oracleconnection.open (); } }
OracleDataReader OracleDataReader = Oraclehelper.getdatareader ("select * FROM table") ; while (Oracledatareader.read ()) { Console.WriteLine (oracledatareader[" field "]. ToString ());} Oraclehelper.closeconnection ();
dll:http://download.csdn.net/detail/lelehellow/9868148
Suzhou Gree Air Conditioning Repair
Suzhou Siemens Refrigerator Maintenance
Shanghai Registered Company
C # access to Oracle Database