- 爱易网页
-
ASP.NET教程
- 数据库访问底层(DAL)的设计~贴者有分,嘿嘿,该如何处理
日期:2014-05-19 浏览次数:20428 次
数据库访问底层(DAL)的设计~~贴者有分,嘿嘿
偶自己先帖一个:
大虾表笑话俺^_^
using System;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
namespace com.DataAccess
{
public enum DBType
{
SQL,Access,Oracle
}
public interface IDataAccess
{
IDbConnection Connection { get;}
void Open();
void Close();
void BeginTrans();
void CommitTrans();
void RollBackTrans();
int ExecNonQuery(string cmdText, CommandType cmdType, Hashtable ht);
IDataReader ExecReader(string cmdText, CommandType cmdType, Hashtable ht, bool closeConnection);
DataTable ExecDataTable(string cmdText, CommandType cmdType, Hashtable ht);
DataSet ExecDataSet(string cmdText, CommandType cmdType, Hashtable ht);
object ExecScalar(string cmdText, CommandType cmdType, Hashtable ht);
}
public class SQLAccess : IDataAccess
{
private SqlConnection myCon;
private SqlTransaction myTrans;
private bool inTrans = false;
public SQLAccess(string strConn)
{
myCon = new SqlConnection(strConn);
}
public IDbConnection Connection
{
get { return myCon; }
}
public void Open()
{
if (myCon.State != ConnectionState.Open)