复制代码 代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Collections;
namespace Website.Command
{
/// <summary>
/// WSplus 的摘要说明。
/// </summary>
public class AccessClass : System.Web.UI.Page
{
private static OleDbConnection sconn = null;
public static string _returnValue = "0";
public WSplus()
{
//
// TODO: 在此处添加构造函数逻辑
//
sconn = new OleDbConnection("Provider="Microsoft.Jet.OLEDB.4.0;Data" Source=" + Server.MapPath("/..db.mdb") + ";");
}
/// <summary>
///开启数据
/// </summary>
private static void connOpen()
{
if (sconn.State="=ConnectionState.Closed)"
try
{
sconn.Open();
}
catch (Exception ex)
{
throw new Exception("数据库初始化错误!!!"+ex.Message);
}
}
/// <summary>
/// 关闭数据库
/// </summary>
public void connClose()
{
if (sconn.State ="=" ConnectionState.Open)
try
{
sconn.Close();
}
catch (Exception ex)
{
throw new Exception("OleDb Close Error!"+ex.Message);
}
}
/// <summary>
/// 存储过程型CMD初始化!
/// </summary>
/// <param name="ht"></param>
/// <param name="sCmd"></param>
/// <param name="proc"></param>
private static void ConfigCMD(Hashtable ht,OleDbCommand sCmd,string sqls)
{
if (sCmd ="=" null) throw new ArgumentException("sCmd未初始化");
if (ht != null && ht.Count != 0)
{
IDictionaryEnumerator items = ht.GetEnumerator();
while (items.MoveNext())
sCmd.Parameters.Add(MakeParam(items.Key.ToString(),items.Value.ToString()));
}
sCmd.Connection = sconn;
sCmd.CommandText = sqls;
}
private static void ConfigCMD(ArrayList alist,OleDbCommand sCmd,string sqls)
{
if (sCmd ="=" null) throw new ArgumentException("sCmd未初始化");
if (alist != null && alist.Count != 0)
{
foreach (object items in alist)
{
Command.Model.typeFiles cmt = (Command.Model.typeFiles)items;
sCmd.Parameters.Add(MakeParam(cmt.Fkey.ToString(),cmt.Fvalue1.ToString(),cmt.Fvalue2.ToString()));
}
}
sCmd.Connection = sconn;
sCmd.CommandText = sqls;
}
private static OleDbParameter MakeParam(string key,string value)
{
return new OleDbParameter(key,value);
}
private static OleDbParameter MakeParam(string key,string F1,string F2)
{
OleDbParameter par = null;
if (F2.ToUpper() ="=" "STRING")
{
par = new OleDbParameter(key,OleDbType.VarChar);
}
else if (F2.ToUpper() ="=" "INTEGER")
{
par = new OleDbParameter(key,OleDbType.Integer);
}
else if (F2.ToUpper() ="=" "LSTRING")
{
par = new OleDbParameter(key,OleDbType.LongVarChar);
}
// try
// {
par.Value = F1;
// }
// catch(Exception e)
// {
// throw new Exception(e.Message + " " + key + " " + F1 + " " + F2);
// }
return par;
}
public void ExecConfig(Hashtable ht,string sqls)
{
OleDbCommand cmd="new OleDbCommand();
connOpen();
ConfigCMD(ht,cmd,sqls);
ExecuteNonQuery(cmd);
}
public void ExecConfig(ArrayList alist,string sqls)
{
OleDbCommand cmd="new OleDbCommand();
connOpen();
ConfigCMD(alist,cmd,sqls);
ExecuteNonQuery(cmd);
}
/// <summary>
/// 数据操作
/// </summary>
/// <param name="cmd"></param>
private static void ExecuteNonQuery(OleDbCommand cmd)
{
Command.AccessClass cw = new AccessClass();
try
{
_returnValue = cmd.ExecuteNonQuery().ToString();
}
catch (Exception e) {throw new Exception("Run Exec Error!"+e.Message);}
finally
{
cmd.Parameters.Clear();
cw.connClose();
}
}
/// <summary>
/// sql语句型datatable
/// </summary>
/// <param name="sqls"></param>
/// <returns></returns>
public DataTable ReturnDatatableBySql(Hashtable ht,string sqls)
{
DataTable dt="new DataTable();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(ht,cmd,sqls);
OleDbDataAdapter sda="new OleDbDataAdapter(cmd);
sda.Fill(dt);
cmd.Parameters.Clear();
return dt;
}
public OleDbDataReader getReader(Hashtable ht,string sqls)
{
connOpen();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(ht,cmd,sqls);
OleDbDataReader reader = cmd.ExecuteReader();
return reader;
//reader.Close();
//cmd.Parameters.Clear();
//connClose();
}
public OleDbDataReader getReader(ArrayList alist,string sqls)
{
connOpen();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(alist,cmd,sqls);
OleDbDataReader reader = cmd.ExecuteReader();
return reader;
//reader.Close();
//cmd.Parameters.Clear();
//connClose();
}
public string ReturnValue
{
get
{
return _returnValue;
}
set
{
_returnValue = value;
}
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Collections;
namespace Website.Command
{
/// <summary>
/// WSplus 的摘要说明。
/// </summary>
public class AccessClass : System.Web.UI.Page
{
private static OleDbConnection sconn = null;
public static string _returnValue = "0";
public WSplus()
{
//
// TODO: 在此处添加构造函数逻辑
//
sconn = new OleDbConnection("Provider="Microsoft.Jet.OLEDB.4.0;Data" Source=" + Server.MapPath("/..db.mdb") + ";");
}
/// <summary>
///开启数据
/// </summary>
private static void connOpen()
{
if (sconn.State="=ConnectionState.Closed)"
try
{
sconn.Open();
}
catch (Exception ex)
{
throw new Exception("数据库初始化错误!!!"+ex.Message);
}
}
/// <summary>
/// 关闭数据库
/// </summary>
public void connClose()
{
if (sconn.State ="=" ConnectionState.Open)
try
{
sconn.Close();
}
catch (Exception ex)
{
throw new Exception("OleDb Close Error!"+ex.Message);
}
}
/// <summary>
/// 存储过程型CMD初始化!
/// </summary>
/// <param name="ht"></param>
/// <param name="sCmd"></param>
/// <param name="proc"></param>
private static void ConfigCMD(Hashtable ht,OleDbCommand sCmd,string sqls)
{
if (sCmd ="=" null) throw new ArgumentException("sCmd未初始化");
if (ht != null && ht.Count != 0)
{
IDictionaryEnumerator items = ht.GetEnumerator();
while (items.MoveNext())
sCmd.Parameters.Add(MakeParam(items.Key.ToString(),items.Value.ToString()));
}
sCmd.Connection = sconn;
sCmd.CommandText = sqls;
}
private static void ConfigCMD(ArrayList alist,OleDbCommand sCmd,string sqls)
{
if (sCmd ="=" null) throw new ArgumentException("sCmd未初始化");
if (alist != null && alist.Count != 0)
{
foreach (object items in alist)
{
Command.Model.typeFiles cmt = (Command.Model.typeFiles)items;
sCmd.Parameters.Add(MakeParam(cmt.Fkey.ToString(),cmt.Fvalue1.ToString(),cmt.Fvalue2.ToString()));
}
}
sCmd.Connection = sconn;
sCmd.CommandText = sqls;
}
private static OleDbParameter MakeParam(string key,string value)
{
return new OleDbParameter(key,value);
}
private static OleDbParameter MakeParam(string key,string F1,string F2)
{
OleDbParameter par = null;
if (F2.ToUpper() ="=" "STRING")
{
par = new OleDbParameter(key,OleDbType.VarChar);
}
else if (F2.ToUpper() ="=" "INTEGER")
{
par = new OleDbParameter(key,OleDbType.Integer);
}
else if (F2.ToUpper() ="=" "LSTRING")
{
par = new OleDbParameter(key,OleDbType.LongVarChar);
}
// try
// {
par.Value = F1;
// }
// catch(Exception e)
// {
// throw new Exception(e.Message + " " + key + " " + F1 + " " + F2);
// }
return par;
}
public void ExecConfig(Hashtable ht,string sqls)
{
OleDbCommand cmd="new OleDbCommand();
connOpen();
ConfigCMD(ht,cmd,sqls);
ExecuteNonQuery(cmd);
}
public void ExecConfig(ArrayList alist,string sqls)
{
OleDbCommand cmd="new OleDbCommand();
connOpen();
ConfigCMD(alist,cmd,sqls);
ExecuteNonQuery(cmd);
}
/// <summary>
/// 数据操作
/// </summary>
/// <param name="cmd"></param>
private static void ExecuteNonQuery(OleDbCommand cmd)
{
Command.AccessClass cw = new AccessClass();
try
{
_returnValue = cmd.ExecuteNonQuery().ToString();
}
catch (Exception e) {throw new Exception("Run Exec Error!"+e.Message);}
finally
{
cmd.Parameters.Clear();
cw.connClose();
}
}
/// <summary>
/// sql语句型datatable
/// </summary>
/// <param name="sqls"></param>
/// <returns></returns>
public DataTable ReturnDatatableBySql(Hashtable ht,string sqls)
{
DataTable dt="new DataTable();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(ht,cmd,sqls);
OleDbDataAdapter sda="new OleDbDataAdapter(cmd);
sda.Fill(dt);
cmd.Parameters.Clear();
return dt;
}
public OleDbDataReader getReader(Hashtable ht,string sqls)
{
connOpen();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(ht,cmd,sqls);
OleDbDataReader reader = cmd.ExecuteReader();
return reader;
//reader.Close();
//cmd.Parameters.Clear();
//connClose();
}
public OleDbDataReader getReader(ArrayList alist,string sqls)
{
connOpen();
OleDbCommand cmd="new OleDbCommand();
ConfigCMD(alist,cmd,sqls);
OleDbDataReader reader = cmd.ExecuteReader();
return reader;
//reader.Close();
//cmd.Parameters.Clear();
//connClose();
}
public string ReturnValue
{
get
{
return _returnValue;
}
set
{
_returnValue = value;
}
}
}
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net(C#) Access 数据操作类”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。