• 全部
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
  • 问答

索引超出数组界限问题

qsltz 2004-09-13 09:15:42
有一个datagrid绑定到数据集中的表A,另有文本框绑定到A中的字段.用BindingManagerBase管理数据绑定. 只要鼠标在DATAGRID的滚动条上按一下,然后新增记录就出现错误:
未处理的“System.IndexOutOfRangeException”类型的异常出现在 system.windows.forms.dll 中。

其他信息: 索引超出了数组界限。





Private Sub bnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnadd.Click
Try
bmmaster.EndCurrentEdit()
bmmaster.AddNew()

Catch err As SystemException
MessageBox.Show(err.ToString, "新增记录发生错误", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)

End Try
txuserid.focus

End Sub

Private Sub bncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bncancel.Click
bmmaster.CancelCurrentEdit()

End Sub

Private Sub bndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bndelete.Click
If bmmaster.Count > 0 Then
If MessageBox.Show("确定删除本记录吗?", "删除确认", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = _
DialogResult.Yes Then

bmmaster.RemoveAt(bmmaster.Position)
End If

End If
End Sub


Private Sub bnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnupdate.Click
Dim dsmasterchange As DataSet
dsmaster.EnforceConstraints = False
bmmaster.EndCurrentEdit()
If dsmaster.HasChanges(DataRowState.Deleted) Then
Try
uploaddeletedata()
dsmaster.AcceptChanges()

Catch err As SystemException
dsmaster.RejectChanges()
MessageBox.Show(Err.ToString)

End Try
End If

If dsmaster.HasChanges(DataRowState.Added) Then
Try
uploadadddata()
dsmaster.AcceptChanges()

Catch err As System.Data.OleDb.OleDbException
dsmaster.RejectChanges()
MessageBox.Show(err.ToString)
Catch err As System.SystemException
dsmaster.RejectChanges()
MessageBox.Show(err.ToString)


End Try
End If

If dsmaster.HasChanges(DataRowState.Modified) Then
Try
uploadmodifydata()
dsmaster.AcceptChanges()

Catch err As System.SystemException
dsmaster.RejectChanges()
MessageBox.Show(err.ToString)

End Try
End If
dsmaster.EnforceConstraints = True
MessageBox.Show("数据更新完成!", "消息", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

End Sub


Private Sub bnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnload.Click
dsmaster.EnforceConstraints = False
filldata()
dsmaster.EnforceConstraints = True
MessageBox.Show("数据填入完成!", "消息", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

End Sub
...全文
250 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qsltz 2004-09-14
为什么
回复
liujiayu10 2004-09-14
bmmaster.AddNew()

错误在这个过程里面!
回复
相关推荐
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2004-09-13 09:15
社区公告
暂无公告