急!!求助:recordset的问题

JustSoSoAtCn 2006-01-31 04:53:05
初始化 recordset对象 rstJFFL,只作为datagrid的数据源

With rstJFFL
.Fields.Append "序号", adUnsignedInt 'index:0
.Fields.Append "会计科目", adBSTR 'index:1
.Fields.Append "明细科目", adBSTR 'index:2
'set"发生金额",format:12345678901234.00
.Fields.Append "发生金额", adNumeric 'index:3
.Fields("发生金额").NumericScale = 2
.Fields("发生金额").Precision = 16
.Fields.Append "摘要", adBSTR 'index:4
.Open
End With
Set dgrdJFFL.DataSource = rstJFFL
dgrdJFFL.Columns(0).Width = 450
dgrdJFFL.Columns(0).Locked = True
dgrdJFFL.Columns(1).Width = 1500
dgrdJFFL.Columns(1).Locked = True 'only can select from list,can not edit
dgrdJFFL.Columns(2).Width = 1500
dgrdJFFL.Columns(2).Locked = True 'only can select from list,can not edit
dgrdJFFL.Columns(3).Width = 1500
dgrdJFFL.Columns(3).Alignment = dbgRight
dgrdJFFL.Columns(4).Width = 2000

'of cause ,the recordcount is zero
intJFCount = 0
If rstJFFL.RecordCount = 0 Then
butJFDel.Enabled = False

在butAdd中

Private Sub butJFAdd_Click()
'if the record is empty, can't use the method movelast
If rstJFFL.RecordCount > 0 Then
rstJFFL.MoveLast
End If

'add new row
rstJFFL.AddNew
intJFCount = intJFCount + 1
'set the 序号
rstJFFL.Fields(0) = intJFCount
'set the fsje
rstJFFL.Fields(3).Value = 0#
rstJFFL.Update
butJFDel.Enabled = True
dgrdJFFL.SetFocus

End Sub

在butdel中

Private Sub butJFDel_Click()
If rstJFFL.RecordCount = 0 Then
MsgBox "没有可以删除的记录"
Exit Sub
End If

' set butDFDel_Click()
rstJFFL.Delete
rstJFFL.Update

If rstJFFL.RecordCount = 0 Then
butJFDel.Enabled = False
End If

End Sub

问题:在第一次连续不断的add,后都正常,但是当把所有的recordset的记录都del了

然后又重新加入记录,此时指针停留在最后的记录上,我测了一下 recordset。recordcount,一直都是0,自己用循环来计算也是一样的,要move一下指针或者是del当前的一条记录,recordcount才能反映正确的值;

搞了一个下午,要发疯了。

================================

原来的做法是,遇到的问题是剩下最后一天记录时,不能输入,迷惑!

Private Sub butJFAdd_Click()
'if the record is empty, can't use the method movelast
If rstJFFL.RecordCount > 0 Then
rstJFFL.MoveLast
End If

'add new row
rstJFFL.AddNew
intJFCount = intJFCount + 1
'set the 序号
rstJFFL.Fields(0) = intJFCount
butJFDel.Enabled = True
dgrdJFFL.SetFocus

DJPZ_KM_JF.bUseKM = True 'now can use formKJKM

End Sub

Private Sub butJFDel_Click()
If rstJFFL.RecordCount = 0 Then
MsgBox "没有可以删除的记录"
Exit Sub
End If

rstJFFL.Delete
intJFCount = intJFCount - 1
rstJFFL.MoveNext
'add these codes for deleting the last one continuly
If rstJFFL.EOF Then
rstJFFL.MovePrevious
End If

If rstJFFL.RecordCount = 0 Then
butJFDel.Enabled = False

DJPZ_KM_JF.bUseKM = False 'now can not use formKJKM
End If


End Sub
...全文
86 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JustSoSoAtCn 2006-01-31
  • 打赏
  • 举报
回复
来的做法是,遇到的问题是剩下最后一 天 记录时,不能输入,迷惑!
应该是:
来的做法是,遇到的问题是剩下最后一 条 记录时,在界面上不能输入,迷惑!



7,763

社区成员

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

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