如何判断一个access库中,某个表是否存在?在线等!!

ffllyy 2004-01-04 10:52:12
如题
...全文
144 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ffllyy 2004-01-05
  • 打赏
  • 举报
回复
谁能给个具体点的做法吗
bluesmile979 2004-01-04
  • 打赏
  • 举报
回复
select object_id('tableName') --如果没有则为null
ffllyy 2004-01-04
  • 打赏
  • 举报
回复
??
sony19791015 2004-01-04
  • 打赏
  • 举报
回复
gz
ffllyy 2004-01-04
  • 打赏
  • 举报
回复
CMyADOApi pMyado;
CString str;
str.Format("select name from test where name ='表名'");
pMyado.DoSql(str);

int CMyADOApi::DoSql(CString sql)
{
CString strsql;
strsql = sql;
try
{
theApp.pRst.CreateInstance("ADODB.Recordset");
theApp.pRst->Open(_bstr_t(strsql),(IDispatch*)theApp.pConn,
adOpenStatic,adLockOptimistic,adCmdText);
return TRUE;
}
catch(_com_error e)
{
CString errorMessage;
errorMessage.Format("打开数据表错误!\nError:%s",e.ErrorMessage());
AfxMessageBox(errorMessage, MB_ICONHAND);
return FALSE;
}
}
这样不行啊,报错,代码是3127,帮忙中找不到这个错代码?能不能举个例子。谢谢
yintongshun 2004-01-04
  • 打赏
  • 举报
回复
select name from sysobjects where name =' 表名' and type = 'U'

如果结果不是为空,则表明此表存在于数所库中。
ffllyy 2004-01-04
  • 打赏
  • 举报
回复
这是这样写的但是程序出错,能不能具体点。
_RecordsetPtr pRst;
CMyADOApi pMyado;
CString str;
str.Format("select boject_id('test')");
if (pRst->Open(_bstr_t(str),(IDispatch*)theApp.pConn,
adOpenStatic,adLockOptimistic,adCmdText)==NULL)
MessageBox("不存在");
taianmonkey 2004-01-04
  • 打赏
  • 举报
回复
pRstSchema = pConnection->OpenSchema(adSchemaTables);


_bstr_t table_name = pRstSchema->Fields->
GetItem("TABLE_NAME")->Value;//获取表的名称

4,011

社区成员

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

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