You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using System.Data.OleDb;
|
||
|
|
||
|
namespace Stone.Common
|
||
|
{
|
||
|
public class MyOleDbDatabase
|
||
|
{
|
||
|
public static OleDbConnection m_oleconn = null;
|
||
|
public static OleDbCommand m_olecmd = null;
|
||
|
public static OleDbParameter m_olepar = null;
|
||
|
/// <summary>
|
||
|
/// 打开Access数据库的连接
|
||
|
/// </summary>
|
||
|
/// <param name="DbPath">要打开的Access数据库Mdb文件的路径</param>
|
||
|
public static void OpenDatabase(string DbPath)
|
||
|
{
|
||
|
m_oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbPath);
|
||
|
m_oleconn.Open();
|
||
|
|
||
|
m_olecmd = m_oleconn.CreateCommand();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 关闭Access数据库
|
||
|
/// </summary>
|
||
|
public static void CloseDatabase()
|
||
|
{
|
||
|
if (m_oleconn != null)
|
||
|
{
|
||
|
if (m_oleconn.State == ConnectionState.Open)
|
||
|
{
|
||
|
m_oleconn.Close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 添加一个参数进去
|
||
|
/// </summary>
|
||
|
/// <param name="ParameterName">参数名称</param>
|
||
|
/// <param name="ParameterValue">参数值</param>
|
||
|
public static void AddParameter(string ParameterName, string ParameterValue)
|
||
|
{
|
||
|
if (m_olepar == null)
|
||
|
{
|
||
|
m_olepar = m_olecmd.CreateParameter();
|
||
|
}
|
||
|
m_olepar = new OleDbParameter(ParameterName, ParameterValue);
|
||
|
m_olecmd.Parameters.Add(m_olepar);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 执行一行SQL语句
|
||
|
/// </summary>
|
||
|
/// <param name="CommandText"></param>
|
||
|
/// <returns>影响的记录的行数</returns>
|
||
|
public static int ExecuteNonQuery(string CommandText)
|
||
|
{
|
||
|
int result = -1;
|
||
|
m_olecmd.CommandText = CommandText;
|
||
|
result = m_olecmd.ExecuteNonQuery();
|
||
|
m_olecmd.Parameters.Clear();
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 执行一行SQL语句,返回一个DataSet
|
||
|
/// </summary>
|
||
|
/// <param name="CommandText"></param>
|
||
|
/// <returns>返回一个DataSet</returns>
|
||
|
public static DataSet ExecuteDataSet(string CommandText)
|
||
|
{
|
||
|
DataSet ds = new DataSet();
|
||
|
m_olecmd.CommandText = CommandText;
|
||
|
OleDbDataAdapter dap = new OleDbDataAdapter(m_olecmd);
|
||
|
dap.Fill(ds);
|
||
|
return ds;
|
||
|
}
|
||
|
}
|
||
|
}
|