zoukankan      html  css  js  c++  java
  • ManagedDataAccess连数据库

     

    Oracle官方的托管数据库访问组件,单DLL,Oracle.ManagedDataAccess.dll,不安装Oracle客户端,不区分32/64位, 直接引用即可。

    与非托管程序为Oracle.DataAccess.dll相比,不支持BulkCopy和CustomType等。

    下载

    https://www.oracle.com/database/technologies/odac-downloads.html

    或者

    nuget

    文档

    https://docs.oracle.com/cd/E11882_01/win.112/e23174/toc.htm

     类介绍

    OracleCommand

    OracleCommandBuilder

    OracleConnection

    OracleDataAdapter 

    OracleDatabase 

    OracleDataReader

    OracleError 

    OracleErrorCollection

    OracleException

    OracleInfoMessageEventArgs

    OracleParameter 

    OracleParameterCollection

    OraclePermission

    OraclePermissionAttribute

    OracleRowUpdatedEventArgs

    OracleRowUpdatingEventArgs

    OracleTransaction

    DataSet接收

                DataSet ds = new DataSet();
                string str = @"Data Source=xxx:1521/orcl; User Id=xxx; password=xxx;Pooling=false";
                string sql = "select * from T_MD_SCALE";
                try
                {
                    using (OracleConnection conn = new OracleConnection(str))
                    {
                        conn.Open();
                        if (conn.State == ConnectionState.Open)
                        {
                            OracleDataAdapter da = new OracleDataAdapter(sql, conn);
                            da.Fill(ds, "ds");
                        }
                        //测试
                        Console.ReadKey();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

     获得某个表的列名和类型

            static void Main(string[] args)
            {
                DataSet ds = new DataSet();
                string str = @"Data Source=xxx:1521/orcl; User Id=xxx; password=xxx;Pooling=false";
                string sql = "select * from T_MD_SCALE";
                try
                {
                    using (OracleConnection conn = new OracleConnection(str))
                    {
                        conn.Open();
                        if (conn.State == ConnectionState.Open)
                        {
                            OracleCommand cmd = new OracleCommand(sql, conn);
                            OracleDataReader reader = cmd.ExecuteReader();
                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                //
                                Console.WriteLine("列名是:"+reader.GetName(i));
                                Console.WriteLine("该列类型:" + reader.GetFieldType(i));
                                Console.WriteLine("-----------------------------");
                            }
                        }
                      //测试
                        Console.ReadKey();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

     获取表的架构

            static void Main(string[] args)
            {
                DataSet ds = new DataSet();
                string str = @"Data Source=192.166.208.52:1521/orcl; User Id=IMES_PMS1; password=pms1;Pooling=false";
                string sql = "select * from T_MD_SCALE";
                try
                {
                    using (OracleConnection conn = new OracleConnection(str))
                    {
                        conn.Open();
                        if (conn.State == ConnectionState.Open)
                        {
                            OracleCommand cmd = new OracleCommand(sql, conn);
                            OracleDataReader reader = cmd.ExecuteReader();
                            //架构
                            DataTable dt = reader.GetSchemaTable();
                        }
                      //测试
                        Console.ReadKey();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

    配合上查询数据库的所有表名

    select * from tab

    就可以自定义生成model和dal了

  • 相关阅读:
    缓冲区溢出漏洞实验
    编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能
    预备作业01
    20155335俞昆的第2次随笔
    20155335俞昆
    团队博客
    小组项目第三周(20145101、20145102、20145124、20145203)
    小组项目第二周(20145101、20145102、20145124、20145203)
    小组项目第一周(20145101、20145102、20145124、20145203)
    项目总结
  • 原文地址:https://www.cnblogs.com/buchizaodian/p/12835610.html
Copyright © 2011-2022 走看看