. Net successive Oracle databases (Winform), oraclewinform
Previously, I used Asp. Net to connect to Oracle 10 Gb. Recently I wanted to write a small program, so I chose Winform. After a long time, I found that Winform and Asp. Net have some differences in connecting to Oracle.
Difference 1: Reading configuration files is different:
If you want to connect to the database through the configuration file, the Winform configuration file is App. config, and Asp. Net configuration file is Web. config.
Difference 2: The referenced namespace is different:
To retrieve the information in the Configuration file, Winform must reference using System. Configuration (and right-click "add reference"-> "Using Configuration" in. Net components on the project ").
Add the App. config file Configuration:
<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <connectionStrings> <add name = "connString" connectionString = "data source = network service name; User Id = username; Password = Password; "/> </connectionStrings> </configuration>
The following code is provided:
Using System. data. oracleClient; using System. configuration; namespace ItemMaintian {public partial class Form1: Form {ClsCommon Common = new ClsCommon (); public string connString = ConfigurationManager. connectionStrings ["connString"]. connectionString; OracleConnection conn = new OracleConnection (connString); string strSql = "select * from hthis. p_subsys "; conn. open (); OracleCommand comm = new OracleCommand (strSql, conn); OracleDataAdapter oadp = new OracleDataAdapter (comm); DataSet ds = new DataSet (); oadp. fill (ds); for (int I = 0; I <ds. tables [0]. rows. count; I ++) {chkb_subsys.Items.Add (ds. tables [0]. rows [I] [2]);} conn. close ();}View Code