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;
///
/// 打开Access数据库的连接
///
/// 要打开的Access数据库Mdb文件的路径
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();
}
///
/// 关闭Access数据库
///
public static void CloseDatabase()
{
if (m_oleconn != null)
{
if (m_oleconn.State == ConnectionState.Open)
{
m_oleconn.Close();
}
}
}
///
/// 添加一个参数进去
///
/// 参数名称
/// 参数值
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);
}
///
/// 执行一行SQL语句
///
///
/// 影响的记录的行数
public static int ExecuteNonQuery(string CommandText)
{
int result = -1;
m_olecmd.CommandText = CommandText;
result = m_olecmd.ExecuteNonQuery();
m_olecmd.Parameters.Clear();
return result;
}
///
/// 执行一行SQL语句,返回一个DataSet
///
///
/// 返回一个DataSet
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;
}
}
}