C#连接Access数据库的代码
如下c#代码实现连接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;DataSource=c:\test.mdb"; string strSQL = "INSERT INTO Employee(FirstName, LastName) VALUES('FirstName', 'LastName')" ; // create Objects of ADOConnection and ADOCommand OleDbConnection conn = new OleDbConnection(strDSN); OleDbCommand cmd = new OleDbCommand( strSQL, conn ); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(Oooops. I did it again:\n{0}, e.Message); } finally { conn.Close(); } } }