c# 连接access2007且查询

 和连接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 } } }

你可能感兴趣的:(String,Security,C#,Class,Access,dataset)