> 데이터 베이스 > MySQL 튜토리얼 > DBHelper连接oracle数据库类

DBHelper连接oracle数据库类

WBOY
풀어 주다: 2016-06-07 15:38:52
원래의
1859명이 탐색했습니다.

%-- Name: Author: Description: --% %@ CodeTemplate Language=C# TargetLanguage=Text Src= Inherits= Debug=False Description=Template description here. % %@ Property Name=SampleStringProperty Type=System.String Default=SomeValue Optional=True

Name:
Author: 
Description: 
--%>





using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;

namespace WindowsFormsApplication1
{
    public class DBHelper
    {
        public static string ConnString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["db"].ConnectionString;
            }
        }
        public static OracleConnection Connection
        {
            get
            {
                return new OracleConnection(ConnString);
            }
        }


        public static int ExecuteCommand(string sql)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Connection.Open();
            try
            {
                int result = cmd.ExecuteNonQuery();
                return result;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
        }

        public static int ExecuteCommand(string sql, OracleParameter[] values)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Connection.Open();
            try
            {
                cmd.Parameters.AddRange(values);
                return cmd.ExecuteNonQuery();
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
        }

        public static int GetScalar(string sql)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Connection.Open();
            try
            {
                int result = Convert.ToInt32(cmd.ExecuteScalar());
                return result;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
        }

        public static int GetScalar(string sql, OracleParameter[] values)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Connection.Open();
            try
            {
                cmd.Parameters.AddRange(values);
                int result = Convert.ToInt32(cmd.ExecuteScalar());
                return result;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
        }

        public static OracleDataReader GetReader(string sql)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Connection.Open();
            OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return reader;
        }

        public static OracleDataReader GetReader(string sql, OracleParameter[] values)
        {
            OracleCommand cmd = new OracleCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            cmd.Connection.Open();
            OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return reader;
        }

        public static DataSet GetDataSet(string sql)
        {
            DataSet ds = new DataSet();
            OracleCommand cmd = new OracleCommand(sql, Connection);
            try
            {
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(ds);
                return ds;
            }
            finally
            {
                cmd.Connection.Dispose();
            }
        }

        public static DataSet GetDataSet(string sql, OracleParameter[] values)
        {
            DataSet ds = new DataSet();
            OracleCommand cmd = new OracleCommand(sql, Connection);
            try
            {
                cmd.Parameters.AddRange(values);
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(ds);
                return ds;
            }
            finally
            {
                cmd.Connection.Dispose();
            }
        }

    }
}

public string SampleMethod()
{
 return "Method output.";
}

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿