连接Access数据库:
using System;
using System.Data;
using System.Data.OleDb;
class TestADO
{
static void Main(string[] args)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\test.mdb";
string strSQL = "SELECT * FROM employees" ;
OleDbConnection conn = new OleDbConnection(strDSN);
OleDbCommand cmd = new OleDbCommand( strSQL, conn );
OleDbDataReader reader = null;
try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read() )
{
Console.WriteLine("First Name:{0}, Last Name:{1}", reader["FirstName"], reader["LastName"]);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
conn.Close();
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.