using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data;
namespace WebOp.Common
{
class Orcl
{
public static OdbcConnection OrclConn = new OdbcConnection("Dsn=oracleservicename;uid=admin;pwd=password");
//打开数据库连接
public static OdbcConnection getOrclConn()
{
if (OrclConn == null)
{
OrclConn = new OdbcConnection("Dsn=oracleservicename;uid=admin;pwd=password");
}
try
{
if (OrclConn.State != System.Data.ConnectionState.Open)
{
OrclConn.Open();
}
}
catch (Exception ex)
{
return null;
}
return OrclConn;
}
{
try
{
if (OrclConn != null && OrclConn.State != System.Data.ConnectionState.Closed)
{
OrclConn.Close();
}
return true;
}
catch (Exception ex)
{
return false;
}
}
{
OdbcConnection conn = getOrclConn();
string value= string.Empty;
if (conn != null)
{
OdbcCommand cmd = new OdbcCommand(sql);
cmd.Connection = conn;
OdbcDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
value= dr["key"].ToString();
}
dr.Close();
}
return classcode;
}
{
DataSet ds = new DataSet();
OdbcConnection conn = getOrclConn();
if (conn != null)
{
OdbcCommand cmd = new OdbcCommand(sql);
cmd.Connection = conn;
using (OdbcDataAdapter da = new OdbcDataAdapter(cmd))
{
da.Fill(ds);
}
}
return ds;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data;
namespace WebOp.Common
{
class Orcl
{
public static OdbcConnection OrclConn = new OdbcConnection("Dsn=oracleservicename;uid=admin;pwd=password");
//打开数据库连接
public static OdbcConnection getOrclConn()
{
if (OrclConn == null)
{
OrclConn = new OdbcConnection("Dsn=oracleservicename;uid=admin;pwd=password");
}
try
{
if (OrclConn.State != System.Data.ConnectionState.Open)
{
OrclConn.Open();
}
}
catch (Exception ex)
{
return null;
}
return OrclConn;
}
//关闭数据库连接
public static bool closeOrclConn(){
try
{
if (OrclConn != null && OrclConn.State != System.Data.ConnectionState.Closed)
{
OrclConn.Close();
}
return true;
}
catch (Exception ex)
{
return false;
}
}
//获取某个字段
public static string getValue(string sql){
OdbcConnection conn = getOrclConn();
string value= string.Empty;
if (conn != null)
{
OdbcCommand cmd = new OdbcCommand(sql);
cmd.Connection = conn;
OdbcDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
value= dr["key"].ToString();
}
dr.Close();
}
return classcode;
}
//获取dataset
public static DataSet getDataSet(string sql){
DataSet ds = new DataSet();
OdbcConnection conn = getOrclConn();
if (conn != null)
{
OdbcCommand cmd = new OdbcCommand(sql);
cmd.Connection = conn;
using (OdbcDataAdapter da = new OdbcDataAdapter(cmd))
{
da.Fill(ds);
}
}
return ds;
}
}
}