All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
IIS6的PHP最佳配置方法_[PHP教程]
SQL循序渐进(3)-------数据检索_[SQL,Server教程]
符合web标准的媒体播放器代码_JavaScript技术_编程技术
asp.net把输入文字转化成图片_[Asp.Net教程]
Visual,C#,2005快速入门之调用方法_[Asp.Net教程]
XML入门教程:认识学习 XML 元素_[XML教程]
使用ASP.NET中的一点体会[关于代码分离]_[Asp.Net教程]
SQL,Artisan多层查询条件嵌套功能_[SQL,Server教程]
用ASP+CSS实现网页随机背景_[Html教程]
C#网络应用编程基础练习题与答案(八)_[Asp.Net教程]
Reading number is top 10 pictures
Exquisite decoration is not paying too much4
这才是真正的人体艺术4
粉红蕾丝的美女
清醇靓丽的美眉
两个妞在等世界上最短的火车
Sora aoi calligraphy show
2012 national geographic daily picture2
支持判处贩卖儿童者死刑
张家界的玻璃桥
这两天,中国人民到处都可以“看海”了
Download software ranking
dreamweaver8中文版
尖东毒玫瑰A
VC++6.0简体中文版
Tram sex maniac 2 (H) rar bag12
Take off clothes to survival
VeryCD电驴(EasyMule) V1.1.9 Build09081
Unix video tutorial6
Eclipse 4.2.2 For Win32
Unix video tutorial4
White deer villiage
delv published in(发表于) 2014/1/6 8:47:09 Edit(编辑)
Access,通用数据访问类(asp.net,2.0,c#)_[Asp.Net教程]

Access,通用数据访问类(asp.net,2.0,c#)_[Asp.Net教程]

Access 通用数据访问类(asp.net 2.0 c#)_[Asp.Net教程]

仿照以前收集的一个经典sql server数据访问类,稍做修改。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;



///


/// DataAccess 的摘要说明
///

public class DataAccess
{
protected static OleDbConnection conn = new OleDbConnection();
protected static OleDbCommand comm = new OleDbCommand();
public DataAccess()
{
//init
}
private static void openConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source="+ConfigurationManager.AppSettings["myconn"];//web.config文件里设定。
comm.Connection = conn;
try
{
conn.Open();
}
catch (Exception e)
{ throw new Exception(e.Message); }


}

}//打开数据库

private static void closeConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
comm.Dispose();
}
}//关闭数据库


public static void excuteSql(string sqlstr)
{
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
comm.ExecuteNonQuery();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{ closeConnection(); }
}//执行sql语句


public static OleDbDataReader dataReader(string sqlstr)
{
OleDbDataReader dr = null;
try
{
openConnection();
comm.CommandText = sqlstr;
comm.CommandType = CommandType.Text;


dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
try
{
dr.Close();
closeConnection();
}
catch { }
}
return dr;
}//返回指定sql语句的OleDbDataReader对象,使用时请注意关闭这个对象。
public static void dataReader(string sqlstr, ref OleDbDataReader dr)
{
try
{
openConnection();
comm.CommandText = sqlstr;
comm.CommandType = CommandType.Text;
dr=comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
try
{
if (dr != null && !dr.IsClosed)
dr.Close();
}
catch
{
}
finally
{
closeConnection();
}
}
}//返回指定sql语句的OleDbDataReader对象,使用时请注意关闭


public static DataSet dataSet(string sqlstr)
{
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds);

}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return ds;
}//返回指定sql语句的dataset


public static void dataSet(string sqlstr, ref DataSet ds)
{
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}//返回指定sql语句的dataset


public static DataTable dataTable(string sqlstr)
{
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(dt);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dt;
}//返回指定sql语句的datatable
public static void dataTable(string sqlstr, ref DataTable dt)
{
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(dt);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}//返回指定sql语句的datatable


public static DataView dataView(string sqlstr)
{
OleDbDataAdapter da = new OleDbDataAdapter();
DataView dv = new DataView();
DataSet ds = new DataSet();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds);
dv = ds.Tables[0].DefaultView;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dv;
}
//返回指定sql语句的dataview


}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.