Private Sub Command4_Click()
Dim Workc1 As New ADODB.Connection
Dim Workr1 As New ADODB.Recordset
Dim m As Integer
Dim WorkStr3 As String
Dim WorkStr4 As String
WorkStr3 = "provider=sqloledb;user id=sa;pwd=;initial catalog=知易信息系统;datasource=."
WorkStr4 = "select * from 客户档案表"If MSFlexGrid1.Rows > 1 Then
m = MSFlexGrid1.Row
If Trim(MSFlexGrid1.TextMatrix(m, 0)) <> "客户ID号" Then
If Trim(MSFlexGrid1.TextMatrix(m, 1)) <> "客户名称" Then
If MsgBox("真的要删除" & Trim(MSFlexGrid1.TextMatrix(m, 0)) & "号记录吗?", vbOKCancel, "提示信息") = vbOK Then
Workc1.Open WorkStr3
Workc1.Execute "delete from 客户档案表 where 客户ID号='" & Trim(MSFlexGrid1.TextMatrix(m, 0)) & "'"
Workr1.Open WorkStr4, Workc1
If Workr1.EOF = True Then
Exit Sub
Else
MSFlexGrid1.RemoveItem (m)
End If
End If
End If
End If
End If
End Sub
只剩一条记录时,该记录总是不能动态消失,请指点!!!
Dim Workc1 As New ADODB.Connection
Dim Workr1 As New ADODB.Recordset
Dim m As Integer
Dim WorkStr3 As String
Dim WorkStr4 As String
WorkStr3 = "provider=sqloledb;user id=sa;pwd=;initial catalog=知易信息系统;datasource=."
WorkStr4 = "select * from 客户档案表"If MSFlexGrid1.Rows > 1 Then
m = MSFlexGrid1.Row
If Trim(MSFlexGrid1.TextMatrix(m, 0)) <> "客户ID号" Then
If Trim(MSFlexGrid1.TextMatrix(m, 1)) <> "客户名称" Then
If MsgBox("真的要删除" & Trim(MSFlexGrid1.TextMatrix(m, 0)) & "号记录吗?", vbOKCancel, "提示信息") = vbOK Then
Workc1.Open WorkStr3
Workc1.Execute "delete from 客户档案表 where 客户ID号='" & Trim(MSFlexGrid1.TextMatrix(m, 0)) & "'"
Workr1.Open WorkStr4, Workc1
If Workr1.EOF = True Then
Exit Sub
Else
MSFlexGrid1.RemoveItem (m)
End If
End If
End If
End If
End If
End Sub
只剩一条记录时,该记录总是不能动态消失,请指点!!!
Workr1.Open WorkStr4, Workc1
只剩一条记录时,數據庫先刪除,Workr1.EOF=true
If Workr1.EOF = True Then
Exit Sub
Else
MSFlexGrid1.RemoveItem (m) '就不執行這句了,當然無法移除
End If
應該這樣改:
Workc1.Open WorkStr3
Workc1.Execute "delete from 客户档案表 where 客户ID号='" & Trim(MSFlexGrid1.TextMatrix(m, 0)) & "'"
MSFlexGrid1.RemoveItem (m)