string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=E:/AccessTest/Data.mdb";//?里用的是??路径
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
//查询
//OleDbDataAdapter da = new OleDbDataAdapter("select * FROM TEST", objConnection);
//DataSet ds = new DataSet();
//da.Fill(ds);
//查询
OleDbCommand command = new OleDbCommand("select * FROM TEST where ID = '1'", objConnection);
OleDbDataAdapter daTemp = new OleDbDataAdapter(command);
DataSet dtsTemp = new DataSet();
daTemp.Fill(dtsTemp);
//追加
OleDbCommand insertCommand = new OleDbCommand("INSERT INTO TEST(ID,NAME,AGE) VALUES('4','4','4')", objConnection);
int intInsert = insertCommand.ExecuteNonQuery();
//更新
OleDbCommand updateCommand = new OleDbCommand("UPDATE TEST SET AGE = '8' WHERE ID =" + ":ID", objConnection);
OleDbParameter oleDbParameter = new OleDbParameter("ID", "6");
updateCommand.Parameters.Add(oleDbParameter);
//OleDbCommand updateCommand = new OleDbCommand("UPDATE TEST SET AGE = '8' WHERE ID = '6'", objConnection);
int intUpdate = updateCommand.ExecuteNonQuery();
string strTemp = "'" + "/"" + "'";
//删除
OleDbCommand deleteCommand = new OleDbCommand("DELETE FROM TEST WHERE ID = '3'", objConnection);
int intDelete = deleteCommand.ExecuteNonQuery();
objConnection.Close();
access数据库连接
最新推荐文章于 2017-05-17 10:19:00 发布