2014-04-15 61 views

回答

1

對於Access 2003數據庫文件,如果你的應用程序正在運行32位,你可以用好老噴氣DAO:

// test data 
string tableName = "Members"; 
string oldFieldName = "Photo"; 
string newFieldName = "Photograph"; 

// COM Reference required in C# project: 
//  Microsoft DAO 3.6 Object Library 
// 
var dbe = new DAO.DBEngine(); 
DAO.Database db = dbe.OpenDatabase(@"C:\Users\Public\mdbTest.mdb"); 
DAO.Field fld = db.TableDefs[tableName].Fields[oldFieldName]; 
fld.Name = newFieldName; 
db.Close(); 

要對.ACCDB文件進行操作,或從執行的操作需要安裝以64位運行的C#應用​​程序,更新的Access Database Engine(又名「ACE」)。那麼代碼將是:

// test data 
string tableName = "Members"; 
string oldFieldName = "Photo"; 
string newFieldName = "Photograph"; 

// COM Reference required in C# project: 
//  Microsoft Office 14.0 Access Database Engine Object Library 
// 
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine(); 
Microsoft.Office.Interop.Access.Dao.Database db = dbe.OpenDatabase(@"C:\Users\Public\accdbTest.accdb"); 
Microsoft.Office.Interop.Access.Dao.Field fld = db.TableDefs[tableName].Fields[oldFieldName]; 
fld.Name = newFieldName; 
db.Close();