//---------------------------------------------------------------------
// 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
{
///
/// Static Helper for executing SQL statements against Oracle
/// Requires the ODP.NET provider
///
public class OracleDatabaseHelperEx
{
#region constructor(s)
///
/// Constructor for class, default constructor is private to prevent instances being
/// created as the class only has static methods
///
public OracleDatabaseHelperEx()
{
}
#endregion
#region Static Methods
///
/// Excecutes the SQL statement against the database and returns a DataSet with the results
///
/// Database connection string
/// SQL statement to execute
/// DataSet with the results of the executed command
public DataSet ExecuteSqlCommand( string connectionString, string sqlCommand )
{
DataSet ds = new DataSet() ;
try
{
using ( OracleConnection connection = new OracleConnection( connectionString ) )
{
OracleDataAdapter adapter = new OracleDataAdapter( sqlCommand, connection ) ;
adapter.Fill( ds ) ;
} // connection
}
catch (Exception)
{
throw ;
}
return ds ;
}
///
/// Executes the SQL statement and returns the first column of the first row in the resultset returned by the query.
///
/// Database connection string
/// SQL statement to execute
/// The contents of the first column of the first row in the resultset
public int ExecuteScalar( string connectionString, string sqlCommand )
{
OracleConnection connection = null ;
object col = 0 ;
try
{
connection = new OracleConnection( connectionString ) ;
OracleCommand command = new OracleCommand( sqlCommand, connection ) ;
command.Connection.Open() ;
col = command.ExecuteScalar() ;
}
catch ( Exception )
{
throw;
}
finally
{
connection.Close() ;
}
return Convert.ToInt32( col ) ;
}
///
/// Executes the SQL statement
///
/// Database connection string
/// SQL statement to execute
public void ExecuteNonQuery( string connectionString, string sqlCommand )
{
OracleConnection connection = null ;
try
{
connection = new OracleConnection( connectionString ) ;
OracleCommand command = new OracleCommand( sqlCommand, connection ) ;
command.Connection.Open() ;
command.ExecuteNonQuery() ;
}
catch ( Exception )
{
throw;
}
finally
{
connection.Close() ;
}
}
#endregion
}
}