• C# 操作Orcle数据库


    1.首先添加NuGet:Oracle.ManagedDataAccess

    2.配置连接数据库字符串:Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=***)(PORT=***))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User ID=***;Password=***;

    3.对具体的表进行操作:

    using Oracle.ManagedDataAccess.Client;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConnectOracle
    {
        class Program
        {
            public static string ConnStr= "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=***)(PORT=***))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User ID=***;Password=***;";
            static void Main(string[] args)
            {
                using (OracleConnection conn = new OracleConnection(ConnStr))
                {
                    conn.Open();
                    using (OracleCommand cmd = conn.CreateCommand())
                    {
                        try
                        {
                            cmd.CommandText = "insert into 表名(字段1,字段2) values(值1,值2)";
                            if (cmd.ExecuteNonQuery() > 0)
                            {
                                Console.WriteLine("插入成功!");
                              
                            }
                            else
                            {
                                Console.WriteLine("插入失败!");
                            }
                        }
                        catch (Exception ex)
                        {
    
                            Console.WriteLine("异常:"+ex);
                            cmd.Dispose();
                            conn.Close();
                            conn.Dispose();
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    安全模式下卸载windows installer打包的软件(转)
    OAF页面集成条形码或者二维码
    记一次客户生产环境供应商门户服务器无法访问
    QML显示圆形图片
    QML加载gif
    QML之信号与槽
    QML访问C++类内部
    QML使用C++对象
    C++条件变量
    C/C++程序所占用内存区域
  • 原文地址:https://www.cnblogs.com/zhuzhi0819/p/12877428.html
Copyright © 2020-2023  润新知