惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - samuel's blog

想了很久,我决定换BLOG了. FANSMI音乐下载器原理 启动带参数的线程 哈,俺又回来了! [原创]在C#中实现插件编程 [转]利用XMLHTTP无刷新自动实时更新数据 [转]SYN Flood的C++程序 - samuel's blog 觉得我的BLOG“好像”冷了哦! 师兄写的一个JAVA播放器的源代码 水晶报表的使用技巧 无聊,,,,,吼两声!!!!!!!!!!!!!!! 按需要生成你的"网站导航"栏 ASP.NET中使用托管组件 无聊之极的无聊之“作”,C#加密程序 八种和电脑相关的易发病 最近不更新啦! 看完了没一个能活下的,都笑死了[转] SQL SERVER的视图、存储过程等 国产门户网站和思想强奸!
向面连接的ADO.NET
samuel's blog · 2006-02-19 · via 博客园 - samuel's blog

一个操作数据库的函数。。。为了方便我把它写到了一个单独的文件里。。这里演示了其实现方法。

<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<script runat="server">
 public string v_string_dbname="database.mdb";
 public OleDbConnection conn;
 public OleDbCommand cmd;
 public OleDbDataReader rs;
 
 /***************************************************************************
 * 关闭与数据库的连接
 * 例:DatabaseClose();
 ***************************************************************************/
 public void DatabaseClose()
 {
  rs.Close();
  conn.Close();
 }
 
 /***************************************************************************
 * 数据库操作函数
 * 使用本函数需要在要使用函数的文件中使用 <%@Page Language="C#"%>指令
 * 参数
 *  v_string_sql  SQL语句,要执行的SQL
 *  nonQuery   执行方式,为true的话执行ExecuteNonQuery,适合执行INSERT类语句
 *       为false则会将查询内容输出到rs对象中,适合执行SELECT类语句
 ***************************************************************************/
 public bool DatabaseOption(string v_string_sql, bool nonQuery)
 {
  string v_string_db = Server.MapPath(".") + "\\" + v_string_dbname;
  string v_string_conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + v_string_db;
  bool v_bool_retValue = false;
  
  // 构造数据库操作对象
  conn = new OleDbConnection(v_string_conn);
  cmd = new OleDbCommand(v_string_sql, conn);
  
  // 尝试打开数据库,并读取数据
  try
  {
   conn.Open();
   if(nonQuery)
   {
    cmd.ExecuteNonQuery();
   }
   else
   {
    rs = cmd.ExecuteReader();
   }
   v_bool_retValue = true;
  }
  catch(OleDbException ex)
  {
   v_bool_retValue = false;
   conn.Close();
  }
  
  // 如果是执行的空查询操作那么使用完连接后就关闭它
  if(nonQuery) conn.Close();
  
  return(v_bool_retValue);
 }
</script>