WebConf配置:
<?xml version="1.0"?>
<!--
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings>
<!--***************** 数据库的设置 *****************
!— OperatorDataCode: 数据库操作引擎授权码(自动判断域名)
!— OperatorDataLink: 数据库链接参数(自动判断类型)
!— Access类型: /安装目录/Data/数据库名.mdb
!— SQL Server类型: uid=账号;pwd=密码;database=数据库;server=服务器
**************************************************-->
<add key="OperatorDataCode" value="00000000-00000000"/>
<!add key="OperatorDataLink" value="dbAcc.mdb"/>
<!--add key="OperatorDataLink" value="uid=sa;pwd=sa;database=dbSQL;server=."/-->
<!add key="OperatorDataLink" value="dbAcc.mdb"/>
<!--add key="OperatorDataLink" value="uid=sa;pwd=sa;database=dbSQL;server=."/-->
<!--***********************************************-->
</appSettings>
<connectionStrings/>
<system.web>
<!--
</appSettings>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true"/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Windows"/>
<customErrors mode="RemoteOnly"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
/* •——————————————————————————•
| Title: 智能判断数据源 |
| Project: DBOperatorService.Data |
| Subarea: DataSet |
| Author: ξ箫音ξ |
| Website: www.crfly.com;bbs.52happy.net |
| Created date: 01/16/2007 |
| Changed date: 01/17/2007 |
•——————————————————————————• */
using System;
using System.Configuration;
using System.Web.UI;
using DBOperator.Data;
namespace System.Data
{
public class osdData : Page
{
// Statics
public static string DataLink;
// Constructors
static osdData ()
{
osdData.DataLink = ConfigurationManager.AppSettings["OperatorDataLink"];
}
public osdData ()
{
}
// Methods
public static DataSet DataSet (string sql, int startindex, int num, string dataname)
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return OperatorSql.ExecuteDataSet(sql, startindex, num, dataname);
}
return OperatorAcc.ExecuteDataSet(sql, startindex, num, dataname);
}
public static void ExecuteNonQuery (string sql)
{
if (osdData.DataLink.ToUpper().IndexOf("SERVER") != -1)
{
OperatorSql.ExecuteNonQuery(sql);
}
else
{
OperatorAcc.ExecuteNonQuery(sql);
}
}
public static object Executescalar (string SQL, int i)
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return OperatorSql.ExecuteScalar(SQL, i);
}
return OperatorAcc.ExecuteScalar(SQL, i);
}
}
}
using System;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Reflection;
using DBOperator.Data;
namespace System.Data
{
//[DefaultMember("Item")]
public class osdReader
{
// Instance Fields
public osdData myData;
public OperatorAcc myAcc;
public OperatorSql mySql;
private OleDbDataReader OleDR;
private SqlDataReader SqlDR;
// Constructors
public osdReader (OleDbDataReader dr)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") == -1)
{
this.OleDR = dr;
}
}
public osdReader (SqlDataReader dr)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
this.SqlDR = dr;
}
}
public osdReader(string SQL)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
OperatorSql.Open();
this.SqlDR = new SqlCommand(SQL, OperatorSql.ConnSql).ExecuteReader();
}
else
{
OperatorAcc.Open();
this.OleDR = new OleDbCommand(SQL, OperatorAcc.ConnAcc).ExecuteReader();
}
}
// Methods
public bool Read ()
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return this.SqlDR.Read();
}
return this.OleDR.Read();
}
public void Close ()
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
this.SqlDR.Close();
OperatorSql.Close();
}
else
{
this.OleDR.Close();
OperatorAcc.Close();
}
}
// Properties
public object this[string cs]
{
get
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return this.SqlDR[cs];
}
return this.OleDR[cs];
}
}
}
}
| Title: 智能判断数据源 |
| Project: DBOperatorService.Data |
| Subarea: DataSet |
| Author: ξ箫音ξ |
| Website: www.crfly.com;bbs.52happy.net |
| Created date: 01/16/2007 |
| Changed date: 01/17/2007 |
•——————————————————————————• */
using System;
using System.Configuration;
using System.Web.UI;
using DBOperator.Data;
namespace System.Data
{
public class osdData : Page
{
// Statics
public static string DataLink;
// Constructors
static osdData ()
{
osdData.DataLink = ConfigurationManager.AppSettings["OperatorDataLink"];
}
public osdData ()
{
}
// Methods
public static DataSet DataSet (string sql, int startindex, int num, string dataname)
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return OperatorSql.ExecuteDataSet(sql, startindex, num, dataname);
}
return OperatorAcc.ExecuteDataSet(sql, startindex, num, dataname);
}
public static void ExecuteNonQuery (string sql)
{
if (osdData.DataLink.ToUpper().IndexOf("SERVER") != -1)
{
OperatorSql.ExecuteNonQuery(sql);
}
else
{
OperatorAcc.ExecuteNonQuery(sql);
}
}
public static object Executescalar (string SQL, int i)
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return OperatorSql.ExecuteScalar(SQL, i);
}
return OperatorAcc.ExecuteScalar(SQL, i);
}
}
}
using System;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Reflection;
using DBOperator.Data;
namespace System.Data
{
//[DefaultMember("Item")]
public class osdReader
{
// Instance Fields
public osdData myData;
public OperatorAcc myAcc;
public OperatorSql mySql;
private OleDbDataReader OleDR;
private SqlDataReader SqlDR;
// Constructors
public osdReader (OleDbDataReader dr)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") == -1)
{
this.OleDR = dr;
}
}
public osdReader (SqlDataReader dr)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
this.SqlDR = dr;
}
}
public osdReader(string SQL)
{
this.myData = new osdData();
this.myAcc = new OperatorAcc();
this.mySql = new OperatorSql();
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
OperatorSql.Open();
this.SqlDR = new SqlCommand(SQL, OperatorSql.ConnSql).ExecuteReader();
}
else
{
OperatorAcc.Open();
this.OleDR = new OleDbCommand(SQL, OperatorAcc.ConnAcc).ExecuteReader();
}
}
// Methods
public bool Read ()
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return this.SqlDR.Read();
}
return this.OleDR.Read();
}
public void Close ()
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
this.SqlDR.Close();
OperatorSql.Close();
}
else
{
this.OleDR.Close();
OperatorAcc.Close();
}
}
// Properties
public object this[string cs]
{
get
{
if (osdData.DataLink.ToUpper().IndexOf(";SERVER=") != -1)
{
return this.SqlDR[cs];
}
return this.OleDR[cs];
}
}
}
}
使用方法简单说明:
1、代码对比
1)传统Web网站数据库编程代码
GridView1.DataSource = ds.Tables[TableName1].DefaultView;
GridView1.DataBind();
GridView1.DataBind();
2)使用DBOperator.Data数据库组件
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.DataBind();
2、数据库配置
WebConfig里使用哪个数据库,就打开哪个。
<!add key="OperatorDataLink" value="dbAcc.mdb"/>
<!--add key="OperatorDataLink" value="uid=sa;pwd=sa;database=dbSQL;server=."/-->
3、数据源调用
例如:1) DataSet调用方法:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = osdData.DataSet("SELECT * FROM XiaoYin_User", 0, 0, "dsTable");//使用组
件的scData类,实现DataSet功能
//数据源
GridView1.DataSource = ds;
GridView1.DataSource = ds;
//为GridView绑定数据
GridView1.DataBind();
}
GridView1.DataBind();
}
2) Reader调用方法:
protected void Page_Load(object sender, EventArgs e)
{
//使用scReader类,实现DataReader功能
osdReader dr = new osdReader("SELECT * FROM XiaoYin_User");
{
//使用scReader类,实现DataReader功能
osdReader dr = new osdReader("SELECT * FROM XiaoYin_User");
//循环启动阅读器
while (dr.Read())
{
//输出指定列
Response.Write(dr["u_name"] + "<br>");
}
dr.Close();//关闭阅读器
}
while (dr.Read())
{
//输出指定列
Response.Write(dr["u_name"] + "<br>");
}
dr.Close();//关闭阅读器
}
实现功能:
osdDataSet类
读取(DataSet方式),插入,更新,删除,统计
1,读取
DataSet ds=osdData.DataSet("SELECT * FROM 表 WHERE 条件",开始行,多少行,"虚拟表名");
2,插入
osdData.ExecuteNonQuery("INSERT INTO 表 (列1,列2) VALUES (变量1,变量2)");
3,更新
osdData.ExecuteNonQuery("UPDATE 表 SET 列1=变量A,列2=变量B WHERE 条件");
4,删除
osdData.ExecuteNonQuery("DELETE 表 WHERE 条件");
5,统计
osdData.ExecuteScalar("SELECT * FROM 表 WHERE 条件",统计类型)
统计类型分两种:
int 整型:1
double 带小数点:2
//---------- osdReader类 --------------------
实现功能:读取(DataReader阅读器方式)
调用方法:
osdReader dr=new osdReader("SELECT * FROM 表 WHERE 条件");
//--------------------------------------------
if(dr.Read())
{
//如果特定条件的值存在,立即终止下一行的读取
}
//--------------------------------------------
while(dr.Read)
{
//循环读取符合条件的值
}
//--------------------------------------------
调用读取出来的值:
dr["列名"].ToString();
使用完后关闭:
dr.Close();
全部源码与实例打包下载地址:
http://bbs.crfly.com/19591/ShowPost.aspx
实现功能:读取(DataReader阅读器方式)
调用方法:
osdReader dr=new osdReader("SELECT * FROM 表 WHERE 条件");
//--------------------------------------------
if(dr.Read())
{
//如果特定条件的值存在,立即终止下一行的读取
}
//--------------------------------------------
while(dr.Read)
{
//循环读取符合条件的值
}
//--------------------------------------------
调用读取出来的值:
dr["列名"].ToString();
使用完后关闭:
dr.Close();
全部源码与实例打包下载地址:
http://bbs.crfly.com/19591/ShowPost.aspx