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(); } } } } } }