主要参考这篇文章的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;
}
|
相关阅读:
本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1266697如需转载请自行联系原作者
RQSLT