温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:多层结构会员管理系统源码
当前文件:
mvcMemberShip/DBUtility/DBaccess.cs[5K,2009-6-12 11:48:02],打开代码结构图
mvcMemberShip/DBUtility/DBaccess.cs[5K,2009-6-12 11:48:02],打开代码结构图1using System; 2
using System.Collections; 3
using System.Web; 4
using System.Data; 5
using System.Data.OleDb; 6
using System.Configuration; 7
8
namespace Tmw.DBUtility 9
{ 10
/// <summary> 11
/// Access数据库操作类 12
/// 2007-04-19 13
/// 作者:汤明伟 14
/// </summary> 15
public class DBaccess 16
{ 17
//获取Web.Config数据库连接字符串 18
private static readonly string OleDbConnectionString = "Provider = Microsoft.Jet.OleDb.4.0; Data Source = " + HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings["fallstaraccessConnection"].ConnectionString); 19
//ConfigurationManager.ConnectionStrings["fallstaraccessConnection"].ConnectionString; 20
21
private static OleDbConnection cn; //创建SQL连接 22
private static OleDbDataAdapter sda; //创建SQL数据适配器 23
private static OleDbDataReader sdr; //创建SQL数据读取器 24
private static OleDbCommand cmd; //创建SQL命令对象 25
// private OleDbParameter param; //创建SQL参数 26
private static DataSet ds; //创建数据集 27
private static DataView dv; //创建视图 28
29
/// <summary> 30
/// 打开数据库连接 31
/// </summary> 32
public static void Open() 33
{ 34
... 38
} 39
40
41
/// <summary> 42
/// 关闭数据库连接 43
/// </summary> 44
public static void Close() 45
{ 46
... 53
} 54
55
56
/// <summary> 57
/// 返回DataSet数据集 58
/// </summary> 59
/// <param name="strSql">SQL语句</param> 60
public static DataSet GetDs(string strSql) 61
{ 62
... 70
} 71
72
/// <summary> 73
/// 添加DataSet表 74
/// </summary> 75
/// <param name="ds">DataSet对象</param> 76
/// <param name="strSql">Sql语句</param> 77
/// <param name="strTableName">表名</param> 78
public static void GetDs(DataSet ds, string strSql, string strTableName) 79
{ 80
... 86
} 87
88
89
/// <summary> 90
/// 返回DataView数据视图 91
/// </summary> 92
/// <param name="strSql">Sql语句</param> 93
public static DataView GetDv(string strSql) 94
{ 95
... 99
} 100
101
102
/// <summary> 103
/// 获得DataTable对象 104
/// </summary> 105
/// <param name="strSql">SQL语句</param> 106
/// <returns></returns> 107
public static DataTable GetTable(string strSql) 108
{ 109
... 112
} 113
114
115
/// <summary> 116
/// 获得OleDbDataReader对象 使用完须关闭DataReader,关闭数据库连接 117
/// </summary> 118
/// <param name="strSql">sql语句</param> 119
/// <returns></returns> 120
public static OleDbDataReader GetDataReader(string strSql) 121
{ 122
... 128
} 129
130
131
132
/// <summary> 133
/// 执行Sql语句 134
/// </summary> 135
/// <param name="strSql"></param> 136
public static int RunSql(string strSql) 137
{ 138
... 146
} 147
148
149
150
/// <summary> 151
/// 执行SQL语句,并返回第一行第一列结果 152
/// </summary> 153
/// <param name="strSql">SQL语句</param> 154
/// <returns></returns> 155
public static string RunSqlReturn(string strSql) 156
{ 157
... 169
} 170
public static bool Exists(string strSql) 171
{ 172
DataTable dt = GetTable(strSql); 173
return (dt.Rows.Count > 0) ? true : false; 174
} 175
/// <summary> 176
/// 执行多条SQL语句,实现数据库事务。 177
/// </summary> 178
/// <param name="SQLStringList">多条SQL语句</param> 179
public static void ExecuteSqlTran(ArrayList SQLStringList) 180
{ 181
for (int i = 0; i < SQLStringList.Count; i++) 182
{ 183
string strsql = SQLStringList[i].ToString(); 184
RunSql(strsql); 185
} 186
} 187
} 188
} 189






}