• 大小: 24KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: C#
  • 标签: Oracle  通用类  

资源简介

非常齐全好用的oracle数据库通用DbHelperOracle

资源截图

代码片段和文件信息

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OracleClient;
namespace Com2000888.Utility
{
   
    
    /// 
    /// Copyright (C) 2004-2008 LiTianPing 
    /// 数据访问基础类(基于OracleServer)
    /// 用户可以修改满足自己项目的需要。
    /// 

    /// 
    public abstract class DbHelperOracle
    {
        //数据库连接字符串(web.config来配置)
        //se=DATAbase;uid=sa;pwd=“ />
        public static string connectionString = ConfigurationManager.ConnectionStrings[“connString“].ConnectionString;
        public DbHelperOracle()
        {
        }

        #region  执行简单Oracle语句

        /// 
        /// 执行Oracle语句,返回影响的记录数
        /// 

        /// Oracle语句
        /// 影响的记录数
        public static int ExecuteOracle(string OracleString)
        {
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                using (OracleCommand cmd = new OracleCommand(OracleString connection))
                {
                    try
                    {
                        connection.Open();
                        int rows = cmd.ExecuteNonQuery();
                        return rows;
                    }
                    catch (System.Data.OracleClient.OracleException E)
                    {
                        connection.Close();
                        throw new Exception(E.Message);
                    }
                }
            }
        }

        /// 
        /// 执行多条Oracle语句,实现数据库事务。
        /// 

        /// 多条Oracle语句
        public static void ExecuteOracleTran(ArrayList OracleStringList)
        {
            using (OracleConnection conn = new OracleConnection(connectionString))
            {
                conn.Open();
                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;
                OracleTransaction tx = conn.BeginTransaction();
                cmd.Transaction = tx;
                try
                {
                    for (int n = 0; n < OracleStringList.Count; n++)
                    {
                        string strOracle = OracleStringList[n].ToString();
                        if (strOracle.Trim().Length > 1)
                        {
                            cmd.CommandText = strOracle;
                            cmd.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                }
                catch (System.Data.OracleClient.OracleException E)
                {
                    tx.Rollback();
                    throw new Exception(E.Message);
                }
           

评论

共有 条评论