oraclehelper

来源:互联网 发布:淘宝电商平台 编辑:程序博客网 时间:2024/05/10 20:19

using System;
using System.Data;
using System.Data.OracleClient;

namespace OpenService.BIK.Data
{
 /// <summary>
 /// Oracle数据库数据服务
 /// </summary>
 public class OracleService

{
  public OracleService()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  private static OracleService _service = new OracleService();
  public static OracleService Instance()
  {
   return _service;
  }
  private string _connectionString=OpenService.BIK.Core.ConfigurationManager.ConnectionString;
  public string ConnectionString
  {
   get
   {
    return this._connectionString;
   }
   set
   {
    this._connectionString=value;
   }
  }
  public DataSet GetDataSet(string sql)
  {
   OracleCommand command=new OracleCommand();
   command.CommandText=sql;
   DataSet dataset=GetDataSet(command);
   command.Dispose();
   return dataset;
  }
  public DataSet GetDataSet(System.Data.OracleClient.OracleCommand command)
  {
   DataSet dataset=new DataSet();
   OracleConnection connection=null;
   if(command.Connection==null)
   {
    connection=new OracleConnection(this._connectionString);
    connection.Open();
    command.Connection=connection;
   }
   OracleDataAdapter adapter=new OracleDataAdapter(command);
   adapter.Fill(dataset);
   adapter.Dispose();
   if(connection!=null)
   {
    connection.Close();
    connection.Dispose();
   }
   return dataset;
  }
  public string ExecuteScalar(string sql)
  {
   OracleCommand command=new OracleCommand(sql);
   string _value=GetValue(command);
   command.Dispose();
   return _value;
  }
  public string ExecuteScalar(System.Data.OracleClient.OracleCommand command)
  {
   OracleConnection connection=null;
   if(command.Connection==null)
   {
    connection=new OracleConnection(this._connectionString);
    connection.Open();
    command.Connection=connection;
   }
   object obj=command.ExecuteScalar();
   if(connection!=null)
   {
    connection.Close();
    connection.Dispose();
   }
   if(obj==null)
   {
    return null;
   }
   else
   {
    return obj.ToString();
   }
  }
  public int ExecuteNonQuery(string sql)
  {
   OracleCommand command=new OracleCommand(sql);
   int _value=ExecuteScript(command);
   command.Dispose();
   return _value;
  }
  public int ExecuteNonQuery(System.Data.OracleClient.OracleCommand command)
  {
   OracleConnection connection=null;
   if(command.Connection==null)
   {
    connection=new OracleConnection(this._connectionString);
    connection.Open();
    command.Connection=connection;
   }
   int _value=command.ExecuteNonQuery();
   if(connection!=null)
   {
    connection.Close();
    connection.Dispose();
   }
   return _value;
  }
 }
}

原创粉丝点击