C# l链接Oracle

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Oracle.ManagedDataAccess;
using Oracle.ManagedDataAccess.Client;

namespace OracleTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connstring = ConfigurationManager.AppSettings["connstr"].ToString();
            //            MessageBox.Show(connstring);
            string sql = "select * from XXXX where LOTNUM=:lotnum";

            //OracleParameter par = new OracleParameter(":lotnum", OracleDbType.Varchar2, 10);
            //par.Value = "M910262503";

            OracleParameter par = new OracleParameter(":lotnum", "M910262503");

            using (OracleConnection con = new OracleConnection(connstring))
            {
                con.Open();
                using (OracleCommand cmd = new OracleCommand(sql, con))
                {
                    cmd.Parameters.Add(par);
                    using (OracleDataReader reader = cmd.ExecuteReader())
                    {
                        while(reader.Read())
                        {
                            string layer = reader["LAYER"].ToString();
                        }
                    }
                }
            }

        }
    }
}

  

<appSettings>
<add key="connstr" value="Password=XX;User ID=XXX;Data Source=//10.0.0.0:1521/XXX;"/>
</appSettings>

上一篇:百万级要素优化:基于PG与PostGIS的实时矢量瓦片服务


下一篇:hive的DDL和DML操作(三)