62,046
社区成员
发帖
与我相关
我的任务
分享
和连接sql2005差不多,只需要该连接字符串即可.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace TestAccess
{
class Program
{
static void Main(string[] args)
{
#region Access 2007
Console.WriteLine("Access 2007");
string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";
strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\Database1.accdb;";
strConnection += "Persist Security Info=False";
using (OleDbConnection objConnection = new OleDbConnection(strConnection))
{
objConnection.Open();
OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from Couse", objConnection);
DataSet ds = new DataSet();
myCommandd.Fill(ds, "couse");
DataTable dt = ds.Tables["couse"];
Console.WriteLine(dt.Columns[0].ToString());
Console.WriteLine(dt.Columns[1].ToString());
Console.WriteLine(dt.Columns[2].ToString());
objConnection.Close();
}
#endregion
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2009/05/06/4154255.aspx
<appSettings>
<add key="provider" value="Provider=Microsoft.Jet.OLEDB.4.0;data source="/>
<add key="dbPath" value="~/db\data.mdb"/> //注意必须加~/,代表根目录
</appSettings>
private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("/GuangDong/App_Data/#HS.mdb");
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;