// 连接 OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C://test.mdb;"); cn.Open(); cn.Close(); // 读取数据到DataTable OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C://test.mdb;"); DataTable userTbl = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [User]", cn); da.Fill(userTbl); // 插入一条记录 OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C://test.mdb;"); OleDbCommand cmd = new OleDbCommand("INSERT INTO [User] ([ID], [UserName], [UserPassword]) VALUES (1, 'user_ab', '123')", cn); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); // 更新 OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C://test.mdb;"); OleDbCommand cmd = new OleDbCommand("UPDATE [User] SET [UserPassword]='newpwd' WHERE [UserName]='user_ab'", cn); cn.Open(); cmd.ExecuteNonQuery(); cn.Close();
C#连接ACCESS数据库的几条基本语句
最新推荐文章于 2022-06-24 09:19:11 发布