123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using Oracle.ManagedDataAccess.Client;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- namespace TimedUpload
- {
- public class OracleHelper
- {
- private static string connStr = Constants.UploadDB;
- #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;
- if (parameters != null)
- {
- 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;
- if (parameters != null)
- {
- cmd.Parameters.AddRange(parameters);
- }
- OracleDataAdapter adapter = new OracleDataAdapter(cmd);
- DataTable datatable = new DataTable();
- adapter.Fill(datatable);
- return datatable;
- }
- }
- }
- #endregion
- }
- }
|