Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

click on modify button?

Public Sub DoModify()

Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)

===>>> Dim dr As DataRow = CType(bm.Current, DataRowView).Row <<<===

Dim editform As New EditTransOverride(dr)

Dim retval As DialogResult = editform.ShowDialog()

If retval = DialogResult.OK Then

bm.EndCurrentEdit()

Try

Dim substr As String = dr.Item(4)

substr = substr.Substring(0, 2)

ExecOnTransOverride.upd(dr.Item(1), dr.Item(2), dr.Item(3), dr.Item(4), dr.Item(5), dr.Item(6), dr.Item(8), dr.Item(7), DateTime.Now, dr.Item(7), dr.Item(9))

SqlDataAdapter1.Update(ds, "DsTransOverride1")

ds.Tables("DsTransOverride1").AcceptChanges()

MsgBox("Data Inserted Successfully !", MsgBoxStyle.Information, Me.Text)

Catch se As SqlException

MessageBox.Show(se.Message)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

Else

bm.CancelCurrentEdit()

End If

End Sub

 

 

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.windows.forms.dll

 

Additional information: No value at index -1.

I get an error

===>>> Dim dr As DataRow = CType(bm.Current, DataRowView).Row <<<===

What is going on?

Posted
That's a pretty worthless post - it tells us nothing. Have you checked that bm.Current is index a DataRowView or that it is even set? That is the problem with CType and why you should use DirectCast - if bm.Current isn't of type DataRowView you would get a casting exception which would be much more informative.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...