OracleHelper.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; using System.Data; using System.Configuration; using Oracle.ManagedDataAccess.Client; using System.IO; using System.Collections; using System.Diagnostics; using Oracle.ManagedDataAccess.Types; public class OracleHelper { private static string connStr = "User Id=用户名;Password=密码;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=IP地址)(PORT=端口号)))(CONNECT_DATA=(SERVICE_NAME=实例名)))"; #region 执行SQL语句,返回受影响行数 public static int ExecuteNonQuery(string sql, params OracleParameter[] parameters) { using (OracleConnection conn = new OracleConnection(connStr)) { conn.Open(); using (OracleCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); return cmd.ExecuteNonQuery(); } } } #endregion #region 执行SQL语句,返回DataTable;只用来执行查询结果比较少的情况 public static DataTable ExecuteDataTable(string sql, params OracleParameter[] parameters) { using (OracleConnection conn = new OracleConnection(connStr)) { conn.Open(); using (OracleCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); OracleDataAdapter adapter = new OracleDataAdapter(cmd); DataTable datatable = new DataTable(); adapter.Fill(datatable); return datatable; } } } #endregion }
标签:C#,数据库,cmd,System,sql,Oracle,using,OracleConnection,conn From: https://www.cnblogs.com/ydc2023/p/16996068.html