设为首页 加入收藏

TOP

[C#]分享一个以前的项目使用的DataBaseAccess类(一)
2014-11-24 14:34:34 来源: 作者: 【 】 浏览:5
Tags:分享 一个 以前 项目 使用 DataBaseAccess

最近在整理以前的资料时,看到了以前我们在项目中经常用的一个数据库访问类,虽然现在已经可以用代码生成工具生成比较完整的数据库访问类,但是这个类在我们以前的项目中久经考验,所以我觉得还是比较好用,废话不多说了,上代码:


//======================================================================
//
// filename : DataBaseAccess.cs
//
// description: 1. data base access operation class DataBaseAccess.
// 2. data base access operation help class SQLHelper.
//
//
//
//======================================================================


using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;


namespace DAL
{
#region Database Access
///


/// DataBase Operate Class DataBaseAccess
///

public class DataBaseAccess
{



///


/// DataBase Connection
///

private SqlConnection conn = new SqlConnection(SQLHelper.StrConn);
///
/// DataBase Connection
///

public SqlConnection Conn
{
get
{
return conn;
}
}
///
/// Construct
///

public DataBaseAccess()
{


}


///


/// Destruct
///

~DataBaseAccess()
{
CloseDB();
}


#region "***** Debug Configuration *****"
///


///Judge whether the state is Debug
///

/// if the state is Debug return true,else false
private bool JudgeDebug()
{
bool bIsDebug = false;


#if DEBUG


string strIsDebug = ConfigurationManager.AppSettings["IsDebug"];
bIsDebug = ((bIsDebug || (strIsDebug != null && strIsDebug.Equals("true"))) true : false);


#endif


return bIsDebug;
}


///


/// Output the Debug Information
///

/// Debug Information
private void debug(object objDebugInfo)
{
#if DEBUG
//if open debug,output the debug information into the file(the Directory in which Current programe run and the file name is DebugInfo\[日期].ini)
if (JudgeDebug())
{
string strPath = System.Environment.CurrentDirectory + "\\DebugInfo\\";
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}


try
{
StreamWriter swDebugOutput = new StreamWriter(strPath + DateTime.Now.ToLongDateString() + ".ini", true, System.Text.Encoding.Unicode);
swDebugOutput.Write("time:" + DateTime.Now.ToString() + "\r\n" + objDebugInfo + "\r\n\r\n");
swDebugOutput.Close();
swDebugOutput.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}


#endif
}


#endregion


#region "***** Database Basic Operation *****"


#region ExecuteSql


///


/// Execute SQL(insert,delete,update)command,return the number of the rows which are affected
///

/// SQL Command which will be Executed
/// re
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C# 在winform画面上点击某个区域.. 下一篇C#中生成验证码的类

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: