Net Core教程

C# l链接Oracle

本文主要是介绍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>

这篇关于C# l链接Oracle的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!