UsingSystem; usingSystem. collections. generic; usingSystem. componentModel; usingSystem. data; usingSystem. drawing; usingSystem. linq; usingSystem. text; usingSystem. windows. forms; usingSystem. data. oracleClient; usingSystem. data. sqlClient; name
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; using System. data. oracleClient; using System. data. sqlClient; name
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; using System. data. oracleClient; using System. data. sqlClient; namespace TEST {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {// string connstring = "Data Source = ouc131; user = ouc; password = letu;"; // If an oracle client exists locally, use this connection string connstring = "User Id = ouc; Password = letu; Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 222. 195. *. *) (PORT = 1523) (CONNECT_DATA = (SID = ouc); Unicode = True; "; OracleConnection conn = new OracleConnection (connstring); try {conn. open (); OracleDataAdapter AdapterSelect = new OracleDataAdapter ("select * from text", conn); DataTable dt = new DataTable (); AdapterSelect. fill (dt); dataGridView1.DataSource = dt. defaultView;} catch (Exception ee) {MessageBox. show (ee. message);} finally {conn. close ();}}}}
1. Go to oracle official website to download oracle client instant (http://www.oracle.com/technetwork/topics/winsoft-085727.html unzip the dllbehind to copy to your exefolder. (instantclient-basic-nt-11.2.0.zip supports multi-language, instantclient-basiclite-nt-11.2.0.2.0.zip only supports English, high version of oracle client can link lower version of oracle)
(Or if you install an oracle client on your local machine, you can search for * oci * in the oracle client folder *. dll (oci is an oracle call interface) file. Copy all the searched dll files to your exe folder. Copy the dll files on the Internet)
2. The link string should be written (you can write it into the configuration file, that is, you must write the address, port, instance, user name, and password of the database)
private static string CONNECTION_STRING ="User Id=myUserID;Password=myPassword;Data Source=(DESCRIPTION=" +"(ADDRESS=(PROTOCOL=TCP)(HOST=myserver.server.com)(PORT=yourPort#))" +"(CONNECT_DATA=(SID=yourSID)));";
In this way, you do not need to read the configurations in tnsnames. ora of the installation client.
Note: For programming, you need to put the above dll under your debug or release Directory, which is the same as the directory of the exe file. Otherwise, the file cannot be found and various errors may occur.