主要参考这篇文章的VB代码,。
//修改ACCESS表字段名//dbFile:数据库文件名//tableName:数据库中表名//oldFieldName:原字段名//newFieldName:修改后的字段名BOOL ChangeFieldName(CString dbFile, CString tableName, CString oldFieldName, CString newFieldName){ ADOX::_CatalogPtr pCatalog = NULL; try { pCatalog.CreateInstance(__uuidof(ADOX::Catalog)); CString connStr = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") + dbFile + _T(";"); pCatalog->PutActiveConnection(_bstr_t(connStr)); ADOX::_TablePtr pTable = NULL; ADOX::_ColumnPtr pColumn = NULL; pTable.CreateInstance(_T("ADOX.Table")); pTable->ParentCatalog = pCatalog; pTable = pCatalog->Tables->GetItem(_bstr_t(tableName)); pColumn = pTable->Columns->GetItem(_bstr_t(oldFieldName)); pColumn->Name = _bstr_t(newFieldName); pCatalog->Tables->Refresh(); //刷新 } catch(_com_error &e) { CString errmsg = _T("修改字段名出错:") + CString((LPCSTR)e.Description()); AfxMessageBox(errmsg); return FALSE; } return TRUE;}
相关阅读:
1、
2、
3、
4、
***