1个回答
展开全部
// 连接
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);
以下表为例演示插入跟新操作
表名:User
字段:ID,UserName,UserPassword
// 插入一条记录
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();
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);
以下表为例演示插入跟新操作
表名:User
字段:ID,UserName,UserPassword
// 插入一条记录
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();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询