Biegral
Blog
首页
C#
Java
SQL
Python
JavaScript
Web
Other
ACCSEE数据库简单的封装
Biegral
2007/4/7 20:14:00
6111
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.UI;
using
System.Data.OleDb;
namespace
Solog.AcessTask
...
{
/**/
///
<summary>
///
数据操作层辅助类
///
提供数据源,SQL操作
///
</summary>
public
class
GetData:System.Web.UI.Page
...
{
private
OleDbConnection _myConn;
private
static
string
dbpath
=
HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings[
"
dbpath
"
]);
public
GetData()
...
{
string
ConnectString
=
"
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
"
+
dbpath;
_myConn
=
new
OleDbConnection(ConnectString);
}
public
OleDbConnection MyConn()
...
{
try
...
{
_myConn.Open();
}
catch
(System.Data.OleDb.OleDbException e)
...
{
throw
new
Exception(e.Message);
}
return
_myConn;
}
public
void
closeConn()
...
{
_myConn.Close();
}
public
DataSet GetDataset(
string
sql)
...
{
//
获取DataSet
DataSet ds
=
new
DataSet();
try
...
{
OleDbDataAdapter dap
=
new
OleDbDataAdapter(sql,
this
.MyConn());
dap.Fill(ds);
return
ds;
}
catch
(System.Data.OleDb.OleDbException e)
...
{
throw
new
Exception(e.Message);
}
finally
...
{
closeConn();
}
}
/**/
///
<summary>
///
获取OleDataReader
///
</summary>
///
<param name="sqlstring">
SQL语句
</param>
///
<returns>
OleDataReader
</returns>
public
OleDbDataReader GetReader(
string
sqlstring)
...
{
//
获取IDataReader
OleDbDataReader datareader
=
null
;
OleDbCommand dbcmd
=
new
OleDbCommand(sqlstring,
this
.MyConn());
try
...
{
datareader
=
dbcmd.ExecuteReader(CommandBehavior.CloseConnection);
return
datareader;
}
catch
(System.Data.OleDb.OleDbException e)
...
{
throw
new
Exception(e.Message);
}
}
public
void
excNonQuery(
string
sqlstring)
...
{
//
执行一个无返回值的COMMADND
OleDbCommand exc
=
new
OleDbCommand(sqlstring,
this
.MyConn());
exc.ExecuteNonQuery();
exc.Connection.Close();
}
public
int
excScalar(
string
sqlstring)
...
{
//
执行返回单一INT值
OleDbCommand exc
=
new
OleDbCommand(sqlstring,
this
.MyConn());
int
result
=
Convert.ToInt32(exc.ExecuteScalar());
exc.Connection.Close();
return
result;
}
}
}
本文转载:
CSDN博客
阅读排行
Java面试题全集(上) (1102998 )
Wi-Fi 爆重大安全漏洞,Android、iOS、Windows 等所有无线设备都不安全了 (422532 )
Jquery 使用Ajax获取后台返回的Json数据后,页面处理 (268544 )
Java面试题全集(中) (236957 )
一个非常有用的函数——COALESCE (222966 )
Java面试题全集(下) (220948 )
Uncaught SyntaxError: Unexpected token ) (213439 )
如何用adb连接android手机?(我的亲自经历)------ 顺便说说unable to connect to 192.168.1.100:5555的原因和解决方法 (210652 )
如何利用C/C++逐行读取txt文件中的字符串(可以顺便实现文本文件的复制) (207516 )
yum提示Another app is currently holding the yum lock; waiting for it to exit... (205728 )
分类
C# 【2859 篇】
Java 【2173 篇】
SQL 【1413 篇】
Python 【1538 篇】
JavaScript 【1312 篇】
Web 【951 篇】
Other 【5469 篇】
归档
2022 【830 篇】
2021 【3441 篇】
2020 【5337 篇】
2019 【2404 篇】
2018 【1756 篇】
2017 【257 篇】
2016 【550 篇】
2015 【166 篇】
2014 【252 篇】
2013 【168 篇】
2012 【137 篇】
2011 【26 篇】
2010 【40 篇】
2009 【50 篇】
2008 【74 篇】
2007 【54 篇】
2006 【173 篇】