本文共 1120 字,大约阅读时间需要 3 分钟。
主要参考这篇文章的VB代码,。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | //修改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、