如何得到表中字段的名称和类型?

zhangw1978 2003-10-27 08:45:02
我在ACCESS数据库中一张表“B”,但是我不知道表中有多少个字段,分别是什么,我如何通过程序得到表中这些字段的名称和类型?
...全文
36 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
spwnihao 2003-10-27
  • 打赏
  • 举报
回复
m_pRecordset.CreateInstance(_uuidof(Recordset));
_variant_t TheValue;
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\vctest\\AdoTest\\Debug\\Mydb.mdb;Persist Security Info=False","","",0);
CString strSQL = "select * from REALdata";

BSTR bstrSQL = strSQL.AllocSysString();

m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
表结构不知道,但是知道表的名称就可以了,要是都不知道,那还做什么呀?,给你回答了这么多,可别忘给分呀(^_^)
spwnihao 2003-10-27
  • 打赏
  • 举报
回复
int lFieldcount =m_pRecordset->Fields->GetCount();
for(int i=0;i<lFieldcount;i++)
{
TheValue.vt = VT_I4;
TheValue.lVal = i;
int bb=m_pRecordset->Fields->GetItem(TheValue)->GetType();
CString strname=m_pRecordset->Fields->GetItem(TheValue)->GetName();
}
我就不给你一个一个的试了
Enum类型也可以当作整形看
每一次返回的bb都是一个证书,例如datetime类型返回11
你每一种类型都试一下,把不同的类型的返回整数计下来,以后用就可以了

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧