Oracle数据库Helper类
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
namespace CRM.RCMDLL
{
public class OraclHelper
{
public OleDbTransaction MyTransaction;
public OleDbConnection MyConnection;
public OleDbCommand MyCommand;
//数据库连接关键字
public readonly string strOledbCon;
public OraclHelper()
{
//public static readonly string connString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
//System.Configuration.ConfigurationManager.AppSettings["EmailFrom"]
strOledbCon = System.Configuration.ConfigurationManager.AppSettings["DBConnectionString"];
MyConnection = new OleDbConnection(strOledbCon);
}
public OraclHelper(string as_ConnectString) {
strOledbCon = System.Configuration.ConfigurationManager.AppSettings[as_ConnectString];
MyConnection = new OleDbConnection(strOledbCon);
}
/// <summary>
/// 读取数据表
/// </summary>
/// <param name="as_sqlstr">sql语句</param>
/// <returns></returns>
public OleDbDataReader GetDR(string as_sqlstr)
{
as_sqlstr = ChangeSQLStatement(as_sqlstr);
MyCommand = new OleDbCommand(as_sqlstr, MyConnection);
MyCommand.CommandTimeout = 600;
MyConnection.Open();
OleDbDataReader dr = MyCommand.ExecuteReader();
return dr;
}
/// <summary>
/// 获取数据视图
/// </summary>
/// <param name="as_sqlstr"></param>
/// <returns></returns>
public DataView GetDV(string as_sqlstr)
{
as_sqlstr = ChangeSQLStatement(as_sqlstr);
OleDbDataAdapter MyDA = new OleDbDataAdapter(as_sqlstr, MyConnection);
MyDA.SelectCommand.CommandTimeout = 600;
DataSet ds = new DataSet();
MyDA.Fill(ds, "Result");
DataView dv = ds.Tables["Result"].DefaultView;
MyDA.SelectCommand.Connection.Close();
return dv;
}
/// <summary>
/// 获取数据表
/// </summary>
/// <param name="as_sqlstr"></param>
/// <returns></returns>
public DataTable GetDT(string as_sqlstr)
{
as_sqlstr = ChangeSQLStatement(as_sqlstr);
OleDbDataAdapter MyDA = new OleDbDataAdapter(as_sqlstr, MyConnection);
MyDA.SelectCommand.CommandTimeout = 600;
DataSet ds = new DataSet();
MyDA.Fill(ds, "Result");
DataTable dv = ds.Tables["Result"];
MyDA.SelectCommand.Connection.Close();
return dv;
}
/// <summary>
/// 获取数据表集
/// </summary>
/// <param name="as_sqlstr"></param>
/// <returns></returns>
public DataSet GetDT(string as_sqlstr)
{
as_sqlstr = ChangeSQLStatement(as_sqlstr);
OleDbDataAdapter MyDA = new OleDbDataAdapter(as_sqlstr, MyConnection);
MyDA.SelectCommand.CommandTimeout = 600;
DataSet ds = new DataSet();
MyDA.Fill(ds, "Result");
MyDA.SelectCommand.Connection.Close();
return ds;
}
/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="as_StoreProcedureName">存储过程名称</param>
/// <param name="param">参数</param>
/// <returns></returns>
public bool ExecStoreProcedure(string as_StoreProcedureName, ref OleDbParameter[] param)
{
bool lbl_rtn;
try
{
MyCommand = new OleDbCommand(as_StoreProcedureName, MyConnection);
MyCommand.CommandType = CommandType.StoredProcedure;
if (param != null)
{
for (int i = 0; i < param.Length; i++)
{
MyCommand.Parameters.Add(param[i]);
}
}
MyConnection.Open();
MyCommand.ExecuteNonQuery();
MyConnection.Close();
lbl_rtn = true;
}
catch (Exception ex)
{
MyConnection.Close();
lbl_rtn = false;
}
return lbl_rtn;
}
/// <summary>
/// 获得存储过程返回结果集
/// </summary>
/// <param name="as_StoreProcedureName">存储过程名称</param>
/// <param name="inParam">参数</param>
/// <returns></returns>
public DataTable GetDTFromStoreProcedure(string as_StoreProcedureName, OleDbParameter[] inParam)
{
DataTable dt = new DataTable();
try
{
MyCommand = new OleDbCommand(as_StoreProcedureName, MyConnection);
MyCommand.CommandType = CommandType.StoredProcedure;
if (inParam != null)
{
for (int i = 0; i < inParam.Length; i++)
{
MyCommand.Parameters.Add(inParam[i]);
}
}
OleDbDataAdapter MyDA = new OleDbDataAdapter(MyCommand);
MyDA.Fill(dt);
}
catch (Exception)
{
}
return dt;
}
/// <summary>
/// 事务
/// </summary>
/// <param name="as_sqlstr"></param>
/// <param name="as_ErrMsg"></param>
/// <returns></returns>
public bool UpdateData(string as_sqlstr, ref string as_ErrMsg)
{
bool lbl_rtn;
as_ErrMsg = "";
as_sqlstr = ChangeSQLStatement(as_sqlstr);
MyCommand = new OleDbCommand();
MyCommand.Connection = MyConnection;
MyCommand.Transaction = MyTransaction;
try
{
MyCommand.CommandText = as_sqlstr;
MyCommand.ExecuteNonQuery();
CommitData();
lbl_rtn = true;
}
catch (Exception ex)
{
RollbackData();
lbl_rtn = false;
as_ErrMsg = ex.Message;
}
finally
{
MyCommand.Dispose();
}
return lbl_rtn;
}
/// <summary>
/// 关闭连接
/// </summary>
/// <param name="dr"></param
public void CloseDR(OleDbDataReader dr)
{
dr.Close();
MyConnection.Close();
}
public void OpenConnection()
{
MyConnection.Open();
}
public void StartTransaction()
{
MyTransaction = MyConnection.BeginTransaction(IsolationLevel.ReadCommitted);
}
/// <summary>
/// 事务提交
/// </summary>
public void CommitData()
{
MyTransaction.Commit();
MyConnection.Close();
}
/// <summary>
/// 回滚数据
/// </summary>
public void RollbackData()
{
MyTransaction.Rollback();
MyConnection.Close();
}
/// <summary>
/// 字符替换
/// </summary>
/// <param name="as_sqlstr"></param>
/// <returns></returns>
public string ChangeSQLStatement(string as_sqlstr)
{
string ls_newSqlStr;
ls_newSqlStr = as_sqlstr;
if (strOledbCon.ToUpper().IndexOf("SQLOLEDB") >= 0)
{
ls_newSqlStr = ls_newSqlStr.Replace("sysdate", "getdate()");
ls_newSqlStr = ls_newSqlStr.Replace("nvl(", "isnull(");
ls_newSqlStr = ls_newSqlStr.Replace("to_char(", "convert(varchar,");
ls_newSqlStr = ls_newSqlStr.Replace("to_date(", "convert(date,");
ls_newSqlStr = ls_newSqlStr.Replace("to_number(", "convert(numeric,");
ls_newSqlStr = ls_newSqlStr.Replace("substr(", "substring(");
ls_newSqlStr = ls_newSqlStr.Replace("||", "+");
ls_newSqlStr = ls_newSqlStr.Replace("length(", "len(");
ls_newSqlStr = ls_newSqlStr.Replace("rownum", "row_number() over(order by getdate())");
ls_newSqlStr = ls_newSqlStr.Replace(", 'yyyy-MM-dd'", "");
ls_newSqlStr = ls_newSqlStr.Replace(", 'yyyy-mm-dd'", "");
ls_newSqlStr = ls_newSqlStr.Replace(",'yyyy-MM-dd'", "");
ls_newSqlStr = ls_newSqlStr.Replace(",'yyyy-mm-dd'", "");
ls_newSqlStr = ls_newSqlStr.Replace("'HH24:mm:SS'", "108");
ls_newSqlStr = ls_newSqlStr.Replace("lineno,", "\"lineno\",");
ls_newSqlStr = ls_newSqlStr.Replace("lineno=", "\"lineno\"=");
ls_newSqlStr = ls_newSqlStr.Replace(" lineno ", " \"lineno\" ");
}
return ls_newSqlStr;
}
/// <summary>
/// 获得用户名
/// </summary>
/// <param name="as_staffcode"></param>
/// <returns></returns>
public string GetStaffName(string vip_id)
{
string ls_StaffName = "";
OleDbDataReader dr = GetDR("Select staffname from staff where staffcode = '" + vip_id + "'");
if (dr.Read())
{
ls_StaffName = dr[0].ToString();
CloseDR(dr);
return ls_StaffName;
}
else
{
CloseDR(dr);
return ls_StaffName;
}
}
}
}
Oracle数据库Helper类的更多相关文章
- C# Oracle数据库操作类实例详解
本文所述为C#实现的Oracle数据库操作类,可执行超多常用的Oracle数据库操作,包含了基础数据库连接.关闭连接.输出记录集.执行Sql语句,返回带分页功能的dataset .取表里字段的类型和长 ...
- (转)C# Oracle数据库操作类
原文地址:http://www.cnblogs.com/haibing0107/p/6143922.html using System;using System.Data;using System.C ...
- 连接Oracle数据库帮助类
连接Oracle数据库帮助类,就是把连接Oracle数据库的方法封装起来,只需要在其它页面调用就可,不需要重复写. import java.sql.Connection; import java.sq ...
- C# Oracle数据库操作类
using System; using System.Data; using System.Collections.Generic; using System.Configuration; using ...
- Oracle数据库操作类及连接方法
创建DataBaseAccess引用库下面包括DBConnectionString.cs,DBType.cs ,SysName.cs 三个类 DBConnectionString: using Sys ...
- oracle数据库date类型和mysql数据库datetime类型匹配
oracle数据库有date类型,但是没有datetime类型 mysql数据库既有date类型也有datetime类型. Oracle数据库的date类型和mysql的date类型是不一样的,Ora ...
- C#DbHelperOra,Oracle数据库帮助类 (转载)
主要功能如下数据访问抽象基础类 主要是访问Oracle数据库主要实现如下功能 .数据访问基础类(基于Oracle),主要是用来访问Oracle数据库的. .得到最大值:是否存在:是否存在(基于Orac ...
- .NET/C#/Oracle数据库操作类
public static class OracleHelper { //数据库连接字符串 private readonly static string connstr = Configuration ...
- SpringBoot集成Atomikos使用Oracle数据库mybatis、jta框架
项目中需要数据库分布式事物的实现,于是采用了atumikos技术. 因为生产上需要稳定,所以采用了springboot 1.5.9.RELEASE版本. 本文代码gitlab下载地址: https:/ ...
随机推荐
- Hive编程指南_学习笔记01
第四章: HQl的数据定义 1:创建数据库 create database financials; create database if not exists financials; 2: ...
- 判断QString是否为纯数字,查找自身最长重复子字符串
1.判断QString是否为纯数字 bool IsDigitString(QString strSource) { bool bDigit = false; if (strSource.isEmpty ...
- Python一行代码获得IP地址
比较靠谱的方法, 通过构造UDP包获得本机IP地址 python -c "import socket;print([(s.connect(('8.8.8.8', 53)), s.gets ...
- WIN32常用
//1.设置窗口大小 MoveWindow(hWnd, , , + , + , FALSE); //放在InitInstance用于设置位置与窗口大小 //传递句柄就可以绘图 //2.双缓冲绘图模式 ...
- spark thrift server configuration
# MainApplicationProperties # --master yarn --deploy-mode client 下的配置, client 模式表示,driver 是在本地机器上跑的, ...
- WPF Template
ControlTemplate ControlTemplate:用于定义控件的结构和外观,这样可以将控件外观与控件功能分离开. 在xaml中ControlTemplate通常配置到Style中,通过S ...
- 51nod 1102 面积最大的矩形 && 新疆大学OJ 1387: B.HUAWEI's billboard 【单调栈】+【拼凑段】(o(n) 或 o(nlog(n))
题面1:  题面2:  两道题除了数据范围不同,没有任何差异,两道题都可以o(n)(单调栈),o(nlog(n))(我自己的做法)解决. 解题思路1:(单调栈) 对于每个点找到右边第一个比它小的位 ...
- BZOJ 4870: [Shoi2017]组合数问题 矩阵乘法_递推
Code: #include <cstdio> #include <cstring> #include <algorithm> #define setIO(s) f ...
- electron 新手教程 打包 exe
1.安装nodejs(会自动安装npm) 2.桌面新建文件夹 your-app (下面目录结构) your-app/ ├── package.json ├── main.js └── inde ...
- Linux CentOs6.5误卸载自带python和yum后的解决办法
事故背景:前几天因项目需要,在服务器上搭建python-mysql模块,结果没安装好,于是乎想卸载重装,遂在网上查询卸载python的方法,结果一不小心直接把系统的python删了个干净....... ...