Static Helper for executing SQL statements against Oracle Requires the ODP.NET provider : Oracle « Database ADO.net « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Database ADO.net » OracleScreenshots 
Static Helper for executing SQL statements against Oracle Requires the ODP.NET provider
 
  
//---------------------------------------------------------------------
// File: OracleDatabaseHelperEx.cs
// 
// Summary: 
//
// Copyright (c) Hammersmith & Fulham Bridge Partnership. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

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

namespace BizUnit.Extensions.Utilities
{
  /// <summary>
  /// Static Helper for executing SQL statements against Oracle
  /// Requires the ODP.NET provider
  /// </summary>
  public class OracleDatabaseHelperEx
  {
        #region constructor(s)
        /// <summary>
        /// Constructor for class, default constructor is private to prevent instances being
        /// created as the class only has static methods
        /// </summary>
        public OracleDatabaseHelperEx()
    {
    }
        #endregion

        #region Static Methods
        /// <summary>
        /// Excecutes the SQL statement against the database and returns a DataSet with the results
        /// </summary>
        /// <param name="connectionString">Database connection string</param>
        /// <param name="sqlCommand">SQL statement to execute</param>
        /// <returns>DataSet with the results of the executed command</returns>
        public DataSet ExecuteSqlCommandstring connectionString, string sqlCommand )
        {
            DataSet ds = new DataSet() ;
      try
      {
        using OracleConnection connection = new OracleConnectionconnectionString ) )
        {
          OracleDataAdapter adapter = new OracleDataAdaptersqlCommand, connection ;
          adapter.Fillds ;
        }   // connection
      }
      catch (Exception)
      {
        throw ;
      }
            return ds ;
        }

        /// <summary>
        /// Executes the SQL statement and returns the first column of the first row in the resultset returned by the query.
        /// </summary>
        /// <param name="connectionString">Database connection string</param>
        /// <param name="sqlCommand">SQL statement to execute</param>
        /// <returns>The contents of the first column of the first row in the resultset</returns>
        public int ExecuteScalarstring connectionString, string sqlCommand )
        {
            OracleConnection connection = null ;
            object col = ;

            try 
            {
                connection = new OracleConnectionconnectionString ;
                OracleCommand command = new OracleCommandsqlCommand, connection ;
                command.Connection.Open() ;
                col = command.ExecuteScalar() ;
            }
            catch Exception )
            {
        throw;
            }
            finally 
            {
                connection.Close() ;
            }

            return Convert.ToInt32col ;
        }

        /// <summary>
        /// Executes the SQL statement
        /// </summary>
        /// <param name="connectionString">Database connection string</param>
        /// <param name="sqlCommand">SQL statement to execute</param>
        public void ExecuteNonQuerystring connectionString, string sqlCommand )
        {
            OracleConnection connection = null ;

            try 
            {
                connection = new OracleConnectionconnectionString ;
                OracleCommand command = new OracleCommandsqlCommand, connection ;
                command.Connection.Open() ;
                command.ExecuteNonQuery() ;
            }
            catch Exception )
            {
        throw;
            }
            finally 
            {
                connection.Close() ;
            }
        }
        #endregion
  }
}

   
  
Related examples in the same category
1.How to use an OleDbConnection object to connect to an Oracle database
2.Oracle connection string for C#
3.Connect to an Oracle server
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.