using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.OleDb;namespace JonseTool{ public abstract class AccessHelper { // string s = Application.StartupPath.Replace(@\bin\Debug
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace JonseTool
{
public abstract class AccessHelper
{
// string s = Application.StartupPath.Replace(@"\bin\Debug", "") + @"\Data\#test.mdb";
////JonseTool.AccessHelper.ConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + s + @";Persist Security Info=false;User Id=admin;Password=";
//JonseTool.AccessHelper.ConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + s + @";";
public static string _sConnString = string.Empty;
public static string ConnString
{
get{return _sConnString;}
set{_sConnString = value;}
}
public static bool TestConn(string sConnStr="")
{
OleDbConnection myConn = null;
bool bResult = false;
try
{
if (string.IsNullOrEmpty(sConnStr)) sConnStr = _sConnString;
myConn = new OleDbConnection(_sConnString);
myConn.Open();
}
catch (Exception ex)
{
}
finally
{
if (myConn != null && myConn.State.ToString() == "Open")
bResult = true;
}
myConn.Close();
return bResult;
}
public static DataTable GetDataTable(out string sErr, string sSQL,string sConnStr="",params OleDbParameter[] cmdParams)
{
DataTable dt = null;
sErr = string.Empty;
if (string.IsNullOrEmpty(sConnStr)) sConnStr = _sConnString;
OleDbConnection accConn = null;
try
{
accConn = new OleDbConnection(sConnStr);
OleDbCommand accCmd = new OleDbCommand(sSQL, accConn);
accConn.Open();
if (cmdParams != null)
{
foreach (OleDbParameter parm in cmdParams)
accCmd.Parameters.Add(parm);
}
OleDbDataAdapter adapter = new OleDbDataAdapter(accCmd);
dt = new DataTable();
adapter.Fill(dt);
accConn.Close();
}
catch (Exception ex)
{
sErr = ex.Message;
}
return dt;
}
// 取dataset
public static DataSet GetDataSet(out string sError, string sSQL, string sConnStr = "", params OleDbParameter[] cmdParams)
{
DataSet ds = null;
sError = string.Empty;
try
{
if (string.IsNullOrEmpty(sConnStr)) sConnStr = _sConnString;
OleDbConnection conn = new OleDbConnection(sConnStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sSQL;
if (cmdParams != null)
{
foreach (OleDbParameter parm in cmdParams)
cmd.Parameters.Add(parm);
}
OleDbDataAdapter dapter = new OleDbDataAdapter(cmd);
ds = new DataSet();
dapter.Fill(ds);
}
catch (Exception ex)
{
sError = ex.Message;
}
return ds;
}
// 取某个单一的元素
public static object GetSingle(out string sError, string sSQL,string sConnStr)
{
DataTable dt = GetDataTable(out sError, sSQL,sConnStr);
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0][0];
}
return null;
}
// 取最大的ID
public static Int32 GetMaxID(out string sError, string sKeyField, string sTableName,string sConnStr=null)
{
DataTable dt = GetDataTable(out sError, "select iif(isnull(max([" + sKeyField + "])),0,max([" + sKeyField + "])) as MaxID from [" + sTableName + "]", sConnStr);
if (dt != null && dt.Rows.Count > 0)
{
return Convert.ToInt32(dt.Rows[0][0].ToString());
}
return 0;
}
// 执行 insert,update,delete 动作,也可以使用事务
public static bool UpdateData(out string sError, string sSQL,string sConnStr="",OleDbParameter[] cmdParams = null, bool bUseTransaction = false)
{
int iResult = 0;
sError = string.Empty;
if (string.IsNullOrEmpty(sConnStr)) sConnStr = _sConnString;
if (!bUseTransaction)
{
try
{
OleDbConnection conn = new OleDbConnection(sConnStr);
if (conn.State != ConnectionState.Open)
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sSQL;
if (cmdParams != null)
{
foreach (OleDbParameter parm in cmdParams)
cmd.Parameters.Add(parm);
}
iResult = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
sError = ex.Message;
iResult = -1;
}
}
else // 使用事务
{
OleDbTransaction trans = null;
try
{
OleDbConnection conn = new OleDbConnection(sConnStr);
if (conn.State != ConnectionState.Open)
conn.Open();
trans = conn.BeginTransaction();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sSQL;
if (cmdParams != null)
{
foreach (OleDbParameter parm in cmdParams)
cmd.Parameters.Add(parm);
}
cmd.Transaction = trans;
iResult = cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
sError = ex.Message;
iResult = -1;
trans.Rollback();
}
}
return iResult > 0;
}
}
}
示意图:

功能介绍:后台功能介绍1.系统管理:(1)基本信息管理包括网站名称,域名,管理员昵称,联系电话,邮箱和网站关键字等等的设置。(2) 密码修改 系统管理员密码修改(3)后台登陆记录查看2.新闻管理:(1)新闻管理包括新闻的修改删除(2)添加新闻可添加文字新闻和图片新闻,采用EWEB编辑器操作简便(3)新闻分类管理可自由的添加和删除新闻分类3.产品管理:(1)管理产品可对数据库现有进行修改和删除(2)
0
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号