您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->达达ASP.NET企业信息管理系统>>App-Code/DataAccess.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:达达ASP.NET企业信息管理系统


当前文件路径:DaDaEnterprise/App_Code/DataAccess.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Data.OleDb; 4using System.Configuration; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.HtmlControls; 9using System.Web.UI.WebControls; 10using System.Web.UI.WebControls.WebParts; 11//作者:宇宙达,上传者:yz7805325 12//源码下载及讨论地址:http://www.51aspx.com/CV/DaDaEnterprise 13/// <summary> 14/// 数据类 15/// </summary> 16public class DataAccess 17{ 18 private static OleDbConnection Conn = new OleDbConnection(); 19 private static OleDbCommand Cmd = new OleDbCommand(); 20 21 public DataAccess() 22 { 23 24 } 25 26 /// <summary> 27 /// 打开连接 28 /// </summary> 29 public static void Open() 30 { 31 if (Conn.State.Equals(ConnectionState.Closed)) 32 { 33 Conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" 34 + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings["ConnStr"].ToString()); 35 Cmd.Connection = Conn; 36 Conn.Open(); 37 } 38 } 39 40 /// <summary> 41 /// 关闭连接 42 /// </summary> 43 public static void Close() 44 { 45 if (Conn.State.Equals(ConnectionState.Open)) 46 Conn.Close(); 47 Conn.Dispose(); 48 } 49 50 51 public static DataSet GetDataSet(string sql) 52 { 53 try 54 { 55 Open(); 56 OleDbDataAdapter Da = new OleDbDataAdapter(sql, Conn); 57 DataSet Ds = new DataSet(); 58 Da.Fill(Ds); 59 return Ds; 60 } 61 catch (Exception e) 62 { 63 throw new Exception(e.Message,e); 64 } 65 finally 66 { 67 Close(); 68 } 69 } 70 71 public static DataTable GetDataTable(string sql) 72 { 73 try 74 { 75 Open(); 76 OleDbDataAdapter Da = new OleDbDataAdapter(sql, Conn); 77 DataTable Dt = new DataTable(); 78 Da.Fill(Dt); 79 return Dt; 80 } 81 catch (Exception e) 82 { 83 throw new Exception(e.Message, e); 84 } 85 finally 86 { 87 Close(); 88 } 89 } 90 91 public static int ExecuteCmd(string sql) 92 { 93 try 94 { 95 Open(); 96 Cmd.CommandType = CommandType.Text; 97 Cmd.CommandText = sql; 98 Cmd.ExecuteNonQuery(); 99 return 1; 100 } 101 catch 102 { 103 return -1; 104 } 105 finally 106 { 107 Close(); 108 } 109 } 110 111 /// <summary> 112 /// 统计记录条数 113 /// </summary> 114 /// <param name="sql"></param> 115 /// <returns></returns> 116 public static int CountCmd(string sql) 117 { 118 try 119 { 120 Open(); 121 Cmd.CommandType = CommandType.Text; 122 Cmd.CommandText = sql; 123 return (int)Cmd.ExecuteScalar(); 124 } 125 catch (Exception e) 126 { 127 throw new Exception(e.Message, e); 128 } 129 finally 130 { 131 Close(); 132 } 133 } 134 135 /// <summary> 136 /// 判断管理员 137 /// </summary> 138 public static void IsAdmin() 139 { 140 if (HttpContext.Current.Session["Admin"] == null && HttpContext.Current.Session["Pwd"] == null) 141 { 142 HttpContext.Current.Response.Write(@"<script>alert('你没有登陆或登陆超时!');location.href='./Default.aspx';</script>"); 143 } 144 } 145} 146
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:达达ASP.NET企业信息管理系统

- 某大学211工程办公室网站源码..

- ASPNET2BBS示例论坛源码

- 塞普森调查问卷系统(Asp.net..

- 南充人NET文章系统开源版

- Vb.net简单新闻系统源码

- FreeTextBox 1.6.3 中文版及源码

- 博易(BlogYi)v1.7.5 项目源文件

- ASP.NET标准三层架构留言本项..

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号