我的数据访问层的源代码(一)
数据访问层 ,也许你会说这根本就算不上数据访问层。但我觉得他是。
/************************
* 金色海洋工作室 —— 数据访问层
*
* 数据访问层(SQL Server 版)
*
* 最后修改时间:2006年8月15日
************************/

using System;
using System.Data;
using System.Data.SqlClient;
using JYK.DataStruct; //结构,用于“实体类”
//using System.Security.Principal;

namespace JYK
{
/// <summary>
/// 存储过程的参数的类型,在输出型的参数里使用。
/// </summary>
public enum ParameterKind
{
Int,Double,Decimal,NVarChar,Bit
}

/// <summary>
/// 这是一个通用的数据访问层接口。对ADO.NET的封装。功能类似于 SQLHelper ,但是比SQLHelper要简洁和高效。
/// </summary>
public sealed class DataAccessLayer
{
#region 属性
private static string errorMsg; //出错信息
private static bool isShowErrorSQL; //是否显示出错的查询语句(包括存储过程名程)
private int executeRowCount; //获取执行SQL查询语句后影响的行数
private SqlCommand cm ; //建立Command对象
private SqlTransaction sqlTrans ; //用于事务处理
private static bool isUseTrans; //是否启用了 .net 的事务处理

/// <summary>
/// 读取出错信息
/// </summary>
public string ErrorMsg
{
get{return errorMsg;}
}

/// <summary>
/// 修改连接字符串,在同时访问两个或两个以上的数据库的时候使用
/// </summary>
public string cnString
{
set{cm.Connection.ConnectionString = value;}
get{return cm.Connection.ConnectionString;}
}

/// <summary>
/// 获取执行SQL查询语句后影响的行数
/// </summary>
public int ExecuteRowCount
{
get{return executeRowCount;}
}

/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
if (isUseTrans)
sqlTrans.Dispose();
errorMsg = null;
cm.Parameters.Clear();
cm.Connection.Close();
cm.Dispose();
}
#endregion

public DataAccessLayer() //构造函数
{
//默认不使用事务
isUseTrans = false;
//获取连接字符串
cm = new SqlCommand();
cm.Connection = new SqlConnection("获取连接字符串");
//JYK.Connection.ConnectionString
//初始化错误信息
errorMsg="0";
isShowErrorSQL = true; //本地运行,显示出错的查询语句(包括存储过程名程)
//isShowErrorSQL = false; //服务器运行,不显示出错的查询语句(包括存储过程名程)
}
内部函数

记录错误日志

//事务日志
事务处理部分。并没有做太多的测试,有不合理的地方请多指教

未完,待续......
}
}
/************************
* 金色海洋工作室 —— 数据访问层
*
* 数据访问层(SQL Server 版)
*
* 最后修改时间:2006年8月15日
************************/
using System;
using System.Data;
using System.Data.SqlClient;
using JYK.DataStruct; //结构,用于“实体类”
//using System.Security.Principal;
namespace JYK
{
/// <summary>
/// 存储过程的参数的类型,在输出型的参数里使用。
/// </summary>
public enum ParameterKind
{
Int,Double,Decimal,NVarChar,Bit
}
/// <summary>
/// 这是一个通用的数据访问层接口。对ADO.NET的封装。功能类似于 SQLHelper ,但是比SQLHelper要简洁和高效。
/// </summary>
public sealed class DataAccessLayer
{
#region 属性
private static string errorMsg; //出错信息
private static bool isShowErrorSQL; //是否显示出错的查询语句(包括存储过程名程)
private int executeRowCount; //获取执行SQL查询语句后影响的行数
private SqlCommand cm ; //建立Command对象
private SqlTransaction sqlTrans ; //用于事务处理
private static bool isUseTrans; //是否启用了 .net 的事务处理
/// <summary>
/// 读取出错信息
/// </summary>
public string ErrorMsg
{
get{return errorMsg;}
}
/// <summary>
/// 修改连接字符串,在同时访问两个或两个以上的数据库的时候使用
/// </summary>
public string cnString
{
set{cm.Connection.ConnectionString = value;}
get{return cm.Connection.ConnectionString;}
}
/// <summary>
/// 获取执行SQL查询语句后影响的行数
/// </summary>
public int ExecuteRowCount
{
get{return executeRowCount;}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
if (isUseTrans)
sqlTrans.Dispose();
errorMsg = null;
cm.Parameters.Clear();
cm.Connection.Close();
cm.Dispose();
}
#endregion
public DataAccessLayer() //构造函数
{
//默认不使用事务
isUseTrans = false;
//获取连接字符串
cm = new SqlCommand();
cm.Connection = new SqlConnection("获取连接字符串");
//JYK.Connection.ConnectionString
//初始化错误信息
errorMsg="0";
isShowErrorSQL = true; //本地运行,显示出错的查询语句(包括存储过程名程)
//isShowErrorSQL = false; //服务器运行,不显示出错的查询语句(包括存储过程名程)
}
内部函数 
记录错误日志
//事务日志
事务处理部分。并没有做太多的测试,有不合理的地方请多指教
未完,待续......
}
}


浙公网安备 33010602011771号