如何清空表??????????

nbwice 2001-10-01 08:21:16
用Table->EmptyTable()

报错误"... 表正忙...Use".

用Query1->SQL->Add("Delete form kc.db")

报错误"erroe Creating Cursor handle"


Table->First()
while(!Table->Eof)
{
Table->Delete();
Next();
}

总是删不干净,每次能删掉几个,多几次能删干净。

这是怎么回事呀?


lluunn007(玉笛书生【再现江湖】) 回复于2001-9-29 20:03:29 得10分
Table1->CloseDatabase(TDataBase*) 呢?

中的TDataBase*这个参数具体怎么写?



...全文
92 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mrlong 2001-10-05
  • 打赏
  • 举报
回复
try
{
Table->EmptyTable();
}
catch(...)
{
while(!Table->Eof)
Table->Delete();
}
试一下,如不行,可能table被另地方在使用.

ylm163net 2001-10-02
  • 打赏
  • 举报
回复
不好意思,另两个我从来不用,下面只是我的猜测

报错误"... 表正忙...Use". 你可能在另外一个地方打开此表但未关闭

第二个原因,先看一下bcb的帮助
Calls CheckBrowseMode to post any pending changes to a prior record if necessary.
Calls the BeforeDelete event handler.
Deletes the record.
Frees the buffers allocated for the record.
1。 Puts the dataset into dsBrowse mode.
2。 Resynchronizes the dataset to position the cursor on the next undeleted record.
Calls the AfterDelete event handler.


1。表明delete后,Table自动进入dsBrowse状态,因此你应该Table->Edit()后再delete
2.表明,delete后,Table自动定位到下一条纪录,因此,不需要next

因此,完整的写法应为:
Table->First()
while(!Table->IsEmpty())
{
Table->Edit();
Table->Delete();
// Next();此句不要
}


nbwice 2001-10-01
  • 打赏
  • 举报
回复
nbwice 2001-10-01
  • 打赏
  • 举报
回复
哦,多谢,

你知道那另两个是怎么回事吗?
ylm163net 2001-10-01
  • 打赏
  • 举报
回复
Open当然不行,Open返回一个记录集,
而delete from ...并不返回纪录,
因此程序会报错,尽管delete已经成功执行
ExecSQL执行一段sql命令,不要求返回什么结果
nbwice 2001-10-01
  • 打赏
  • 举报
回复
我用的是query->Open()

不行吗?这有什么不同?
ylm163net 2001-10-01
  • 打赏
  • 举报
回复
使用query1->ExecSQL()即可

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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