. Net successive Oracle databases (Winform), oraclewinform

Source: Internet
Author: User

. 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.