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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.