vb怎么用mshflexgrid实时删除、清空数据库
请教各位大神们,我这个为什么总是删除不了数据库的内容,只是把当前mshflexgrid表格上的数据删了,下次再查询的时候原来删除的内容依旧还在?我用了rs.Update MSHFlexGrid1.Refresh都没有反应,要么就是报错对象关闭时不允许操作。还有清空的话清空不了mshflexgrid表格,只有下次再打开这个表格或者再次查询的时候才显示把表格清空了??
Private Sub Command2_Click()
'连接数据库
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & _
App.Path & "\设计计算.mdb;Persist Security Info=False" '连接数据库的驱动字符串并打开数据库
conn.Open
End If
'删除
Dim sql As String
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = conn
sql = "delete from [设计计算] where [管段编号]=' " & MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0) & " ' "
conn.Execute sql
MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
rs.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
Dim i%
For i = 1 To MSHFlexGrid1.rows - 1
MSHFlexGrid1.TextMatrix(i, 0) = i
Next
conn.Close
Set conn = Nothing
End Sub
'清空
Private Sub Command12_Click()
Dim sql$
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & _
App.Path & "\设计计算.mdb;Persist Security Info=False" '连接数据库的驱动字符串并打开数据库
conn.Open
End If
sql = " Delete from [设计计算] "
conn.Execute sql
MsgBox "已清空"
conn.Close
End Sub