1,打开 Access 2010
OleDbConnection pCnn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=E:\\arcgis\\WindowsApp\\Demo\\Database.accdb;Persist Security Info=False;");
pCnn.Open();
2,插入数据
string pQuery = "INSERT into [练习]" + pSqlFields + " " + "values" + pValues;
OleDbConnection pCnn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=E:\\arcgis\\WindowsApp\\Demo\\Database.accdb;Persist Security Info=False;");
pCnn.Open();
// OleDbCommand cmd = new OleDbCommand(query, cn);
// cmd.ExecuteNonQuery();
OleDbCommand pCmd = new OleDbCommand(pQuery, pCnn);
pCmd.ExecuteNonQuery();
pCnn.Close();
3,添加字段
添加一个字段:
pQuery = "ALTER TABLE [练习]" + " " + "Add" + " " + "FieldName"+" "+"字段类型";
添加多个字段(逗号隔开):
pQuery = "ALTER TABLE [练习]" + " " + "Add" + " " + "FieldName1"+" "+"字段类型1"+","+"FieldName2"+" "+"字段类型2";
4,删除表:
DROP TABLE 表名称;
5,创建表:
CREATE TABLE 表名 (字段名称1 LONG, 字段名称2 TEXT) ;
说明,在用C#操纵这些的时候,尤其要注意空格。