Recently saw a lot of links to Oracle database blog, after I measured, the. NET environment to connect to the Oracle database is divided into the following steps:
1. Connecting an Oracle database requires downloading a Oracle.DataAccess.dll file. The address is here Http://pan.baidu.com/s/1ctAsY
2. Open VS, create a new project. Then the project right--adds the reference.
Then browse to find the downloaded Oracle.DataAccess.dll added in.
3. Add using Oracle.DataAccess.Client; this reference.
4. Code:
Private voidBtnselect_click (Objectsender, EventArgs e) { stringconnectionString; stringqueryString; ConnectionString="Data source=oracle; User Id=zjhis; Password=zjhis";//Database connection StringQueryString =string. Format ("SELECT * from mz_mzsfk1 where SFSB = {0}", tbxSfsb.Text.ToString ());//SQL statementsOracleDataAdapter adapter =NewOracleDataAdapter (querystring,connectionstring);//EXECUTE statement, execution result in adapterDataSet ds=NewDataSet (); Adapter. Fill (DS,"MZ_MZSFK1");//populate the DataSet with the execution resultsDataTable dt = ds. tables["MZ_MZSFK1"]; Tbxsfsb.text= dt. rows[0]["SFSB"]. ToString (); Tbxname.text= dt. rows[0]["BRXM"]. ToString (); Tbxxj.text= dt. rows[0]["XJ"]. ToString (); }
Note that I am connected to the data on the server, but do not specify the server IP address when filling in data source (if you write an IP address, such as 192.168.1.4/oracle instead of error). this may be related to the installation of oracle-oraclient10g_home2, but without testing.
5. If you are under the framework of. NET 2.0, you need to delete the using System.Data.linq; This reference.
VS2010 Connecting to Oracle Database (. NET 2.0 supported)