各位大虾:
请教如何将表中记录一次性全部删除?我试过用ADODC1.Recordset.delete一条一条的删,但觉得麻烦,找了一下,说是用 DELETE from tablename和TRUNCATE TABLE from tablename语句均可以一次删除表中的数据,我试了好几次,总是报错:
1. adodc1.connecttionstring=....
adodc1.execute "delete from tablename"
2. adodc1.connecttionstring=....
adodc1.recordsource="delete from tablename"
adodc1.refresh
第二中好象删了,但adodc1.refresh报错,我也不知道adodc1.refresh该不该要。另外,听说delete只是做删除标记,并不真正删除,若想真正删除该加什么语句?
请问各位大哥大姐,到底该怎么写啊? 先谢谢了!
请教如何将表中记录一次性全部删除?我试过用ADODC1.Recordset.delete一条一条的删,但觉得麻烦,找了一下,说是用 DELETE from tablename和TRUNCATE TABLE from tablename语句均可以一次删除表中的数据,我试了好几次,总是报错:
1. adodc1.connecttionstring=....
adodc1.execute "delete from tablename"
2. adodc1.connecttionstring=....
adodc1.recordsource="delete from tablename"
adodc1.refresh
第二中好象删了,但adodc1.refresh报错,我也不知道adodc1.refresh该不该要。另外,听说delete只是做删除标记,并不真正删除,若想真正删除该加什么语句?
请问各位大哥大姐,到底该怎么写啊? 先谢谢了!
应该就可以了
con.Connecttionstring =.......
con.open
con.Execute "Delete from table"一直都用对象,不喜欢用控件,不灵活
Dim cnn As New ADODB.Connection
cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=data1;Data Source=GDYT-WSW"
cnn.Open
SQL = "TRUNCATE TABLE student"
cnn.Execute SQL
cnn.Close
Set cnn = NothingEnd Sub
//要知道你写出adodc1再点上.后,VB会智能提示出它所有的方法,实际上adodc没有execute这个方法,所以肯定是错的,以后请记主善于利用工具这点.
第二中好象删了,但adodc1.refresh报错,我也不知道adodc1.refresh该不该要。另外,听说delete只是做删除标记,并不真正删除,若想真正删除该加什么语句?
//其实你这2个办法都不好,update是没有作用的,refresh会出现关闭错误,用on error resume next也是无法解决的 所以只能循环用Adodc.Recordset.Delete去循环删除.实际上adodc只是ado的封装,你不如用楼上的ado方法