<connectionStrings>
<add name="connStr" connectionString="server=.;uid=home;pwd=;database=EFFristModel"/>
<!--<add name="connStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|EFFristModel.mdb" providerName="System.Data.OleDb"/>-->
</connectionStrings>
Access数据库的SqlHelper
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
namespace CZBK.BookShop.AccessDal
{
public class SqlHelper
{
private readonly static string connectionString =ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
public static DataTable GetTable(string sql, CommandType type, params OleDbParameter[] pars)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
using (OleDbDataAdapter apter = new OleDbDataAdapter(sql, connection))
{
if (pars != null)
{
apter.SelectCommand.Parameters.AddRange(pars);
}
DataTable da = new DataTable();
apter.SelectCommand.CommandType = type;
apter.Fill(da);
return da;
}
}
}
}
}