一、SQLite数据库连接
需要添加System.Data.SQLite的引用
Web.config //配置文件
<appSettings>
<add key="SQLString" value="~\App_Data\Demo.db"/>
</appSettings>
SQLiteHelper.cs //数据库操作类
public static string connectionString = "Data Source=" + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["SQLString"]);
二、SQL Server数据库连接
稍后补上
三、Access数据库连接
SqlHelper.cs //数据库操作类(Web.config不用配置)
public SqlHelper()
{
path = AppDomain.CurrentDomain.BaseDirectory;
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "/App_Data/123.mdb;Persist Security Info=False";
conn = new OleDbConnection(connectionstring);
}
OleDbConnection conn;
public string path;
public string connectionstring;