zoukankan      html  css  js  c++  java
  • WinForm里面连接Oracle数据库

    WinForm里面连接Oracle数据库

               string oradb = "Data Source=(DESCRIPTION="
                 + "(ADDRESS=(PROTOCOL=TCP)(HOST=MyComputerName)(PORT=1521))"
                 + "(CONNECT_DATA=(SERVICE_NAME=DemoDB)));"
                 + "User Id=SYSTEM;Password=************;";
                 
                try
                {
                    OracleConnection conn = new OracleConnection(oradb);
                    conn.Open();
                    
                    string sql = " select * from DemoOP.T_TEST "; // DemoOP是表T_TEST的user
                    OracleCommand cmd = new OracleCommand(sql, conn);
                    cmd.CommandType = CommandType.Text;
                   
                    //大容量数据,可以进行修改,使用DataSet和DataAdapter
                    DataSet ds = new DataSet();
                    OracleDataAdapter da = new OracleDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(ds);
                    dataGridView1.DataSource = ds.Tables[0] ;

                    //使用DataReader,读取数据
                    OracleDataReader dr = cmd.ExecuteReader();
                    while (dr.Read()) // C#
                    {
                        comboBox1.Items.Add(dr["NAME"].ToString());
                    }

           dr.Close();

                    conn.Dispose(); //Close()也可以。
                       
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());

                }
                finally
                {

                }

  • 相关阅读:
    centos7安装kubenetes
    用户密码字典
    curl使用
    docker部署rabbitmq集群
    记一次使用docker搭建fastdfs服务的过程
    filebeat删除多余标签
    Python format格式化输出
    python3 统计NGINX pv uv 最多IP访问
    linux修改网卡名为eth0
    模式查找
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3379065.html
Copyright © 2011-2022 走看看