|
当DB数据库的表记录是空的时候,比如增加第一条记录会出错,请老师怎样修改下,谢谢
Private Sub AddNewListItem()
With ListView1
If blnNewItem = False Then
.ListItems.Add '在最后面新增
Set .SelectedItem = .ListItems(.ListItems.Count)
.SelectedItem.EnsureVisible
intCol = 1
ShowInkEdit
blnNewItem = True
Else
'验证数据完整性,不通过则不写入数据库
Dim lngLastIndex As Long, i As Long
Dim NewID As Object
Set NewID = CreateObject("adodb.recordset")
If Not .SelectedItem Is Nothing Then
lngLastIndex = .ListItems.Count
If CheckDataIntegrity(lngLastIndex) Then
rst.addnew
For i = 1 To .ColumnHeaders.Count - 1
If Len(.ListItems(lngLastIndex).SubItems(i)) Then
rst(i) = .ListItems(lngLastIndex).SubItems(i)
End If
Next
rst.Update
Set NewID = cnn.Execute("SELECT @@IDENTITY", , 1) '新插入行的ID
If Not NewID.EOF Then .ListItems(lngLastIndex).Text = NewID(0)
blnNewItem = False
MsgBox "新增行保存成功"
Else
MsgBox "请先填写之前的新增行!", vbCritical
End If
End If
End If
End With
End Sub |
评分
-
1
查看全部评分
-
|