using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Data.Common;
using System.Collections.Generic;
/// <summary>
/// 数据访问抽象基础类
///
/// </summary>
public class DBBase
{
//数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库.
public static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString1"].ToString();
public DBBase()
{
}
#region 检查用户名是否存在
/// <summary>
/// 检查用户名是否存在,存在返回true,不存在返回false
/// </summary>
/// <param></param>
/// <returns></returns>
public static bool Exists(string strSql)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
connection.Open();
OracleCommand myCmd = new OracleCommand(strSql, connection);
try
{
object obj = myCmd.ExecuteScalar(); //返回结果的第一行一列
myCmd.Parameters.Clear();
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
#endregion
#region 执行简单SQL语句 返回影响的记录数
/// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param>SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString)
{
OracleConnection connection = null;
OracleCommand cmd = null;
try
{
connection = new OracleConnection(connectionString);
cmd = new OracleCommand(SQLString, connection);
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
finally
{
if (cmd != null)
{
cmd.Dispose();
}
if (connection != null)
{
connection.Close();
connection.Dispose();
}
}
}
#endregion