Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Oracle

Public general use code classes and xml files that we've compiled and used over the years:

Oracle support class.

   1:  using System;
   2:  using System.Web;
   3:  using System.Xml;
   4:  using System.Configuration;
   5:  using System.Data;
   6:  using Oracle.ManagedDataAccess.Types;
   7:  using Oracle.ManagedDataAccess.Client;
   8:  using System.Collections;
   9:  using System.Collections.Generic;
  10:  using System.Text;
  11:   
  12:  namespace Ia.Cl.Model.Db
  13:  {
  14:      ////////////////////////////////////////////////////////////////////////////
  15:   
  16:      /// <summary publish="true">
  17:      /// Oracle support class.
  18:      /// </summary>
  19:      /// <remarks> 
  20:      /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  21:      ///
  22:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  23:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  24:      ///
  25:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  26:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  27:      /// 
  28:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  29:      /// 
  30:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  31:      /// </remarks> 
  32:      public class Oracle
  33:      {
  34:          private static OracleConnection oracleConnection;
  35:   
  36:          ////////////////////////////////////////////////////////////////////////////
  37:   
  38:          /// <summary>
  39:          ///
  40:          /// </summary>
  41:          public Oracle()
  42:          {
  43:              oracleConnection = new OracleConnection();
  44:   
  45:              oracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
  46:              oracleConnection.Open();
  47:          }
  48:   
  49:          ////////////////////////////////////////////////////////////////////////////
  50:   
  51:          /// <summary>
  52:          ///
  53:          /// </summary>
  54:          public Oracle(string connectionString)
  55:          {
  56:              oracleConnection = new OracleConnection();
  57:   
  58:              oracleConnection.ConnectionString = connectionString;
  59:              oracleConnection.Open();
  60:          }
  61:   
  62:          ////////////////////////////////////////////////////////////////////////////
  63:   
  64:          /// <summary>
  65:          ///
  66:          /// </summary>
  67:          public bool Sql(string sql)
  68:          {
  69:              // 
  70:              bool b;
  71:              OracleCommand oco;
  72:   
  73:              oco = null;               
  74:   
  75:              try
  76:              {
  77:                  oco = new OracleCommand();
  78:   
  79:                  oco.Connection = oracleConnection;
  80:                  oco.CommandText = sql;
  81:                  oco.CommandType = CommandType.Text;
  82:   
  83:                  oco.ExecuteNonQuery();
  84:   
  85:                  b = true;
  86:              }
  87:              catch (OracleException)
  88:              {
  89:                  b = false;
  90:              }
  91:              catch (Exception)
  92:              {
  93:                  b = false;
  94:              }
  95:              finally
  96:              {
  97:                  oco.Dispose();
  98:              }
  99:   
 100:              return b;
 101:          }
 102:   
 103:          ////////////////////////////////////////////////////////////////////////////
 104:   
 105:          /// <summary>
 106:          ///
 107:          /// </summary>
 108:          public DataTable Select(string sql)
 109:          {
 110:              DataSet ds = new DataSet();
 111:              DataTable dt = new DataTable();
 112:              OracleCommand oco;
 113:              OracleDataReader dr;
 114:   
 115:              dt = null;
 116:              oco = null;
 117:              dr = null;
 118:   
 119:              try
 120:              {
 121:                  dt = new DataTable();
 122:                  oco = new OracleCommand();
 123:   
 124:                  oco.Connection = oracleConnection;
 125:                  oco.CommandText = sql;
 126:                  oco.CommandType = CommandType.Text;
 127:   
 128:                  dr = oco.ExecuteReader();
 129:                  dt.Load(dr);
 130:              }
 131:              catch (OracleException)
 132:              {
 133:              }
 134:              catch (Exception)
 135:              {
 136:              }
 137:              finally
 138:              {
 139:                  dr.Dispose();
 140:                  oco.Dispose();
 141:              }
 142:   
 143:              return dt;
 144:          }
 145:   
 146:          ////////////////////////////////////////////////////////////////////////////
 147:          ////////////////////////////////////////////////////////////////////////////
 148:      }
 149:  }