Index 2 is not non-negative and below total rows count.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

I'm getting this error on a ASP .NET apps:

Index 2 is not non-negative and below total rows count.

Line 443:
Line 444: Dim ParentTableView As New
DataView(DsSellers1.Tables("SELLERS"))
Line 445: Dim CurrentRowView As DataRowView =
ParentTableView(Me.cboSellers.SelectedValue)
Line 446:
Line 447: grdSellers.DataSource =
CurrentRowView.CreateChildView("SellersRelation")

Stop at Line 445. Here is my source code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
If Not Page.IsPostBack Then
'Fill all DataAdapters into DsSellers dataset.
Me.daSellers.Fill(Me.DsSellers1)
Me.daDoc_Type.Fill(Me.DsSellers1)
Me.daOccupancy.Fill(Me.DsSellers1)
Me.daProduct_Code.Fill(Me.DsSellers1)
Me.daProperty_Type.Fill(Me.DsSellers1)
Me.daPurpose.Fill(Me.DsSellers1)

'Data bind all data to their controls.
Me.cboSellers.DataBind()
End If

Catch ex As Exception
Response.Write(ex.Message)
Finally
Me.ConnWBOC5177.Close()
Me.ConnWBOC5177.Dispose()
End Try

End Sub

Private Sub cboSellers_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboSellers.SelectedIndexChanged
Dim ParentColumn As DataColumn
Dim ChildColumn As DataColumn

ParentColumn = DsSellers1.Tables("SELLERS").Columns("SELLER_ID")
ChildColumn =
DsSellers1.Tables("DOC_TYPE_LISTING").Columns("SELLER_ID")

Dim drSellers As New DataRelation("SellersRelation", ParentColumn,
ChildColumn)
DsSellers1.Relations.Add(drSellers)

Dim ParentTableView As New DataView(DsSellers1.Tables("SELLERS"))
Dim CurrentRowView As DataRowView =
ParentTableView(Me.cboSellers.SelectedValue)

grdSellers.DataSource =
CurrentRowView.CreateChildView("SellersRelation")
grdSellers.DataBind()
End Sub

Can someone help me? I just want to able find related data from the
DropDownList control to the Datagrid use DataRelation object. The Datagrid
will be using it's own queries for Select, Insert, Delete, Update.
 
You are trying to access a row that does not exist. You know your code and
data - up to you to figure out why a row that you expect to be there is not.

Most likely it is because you are only retrieving data the first time the
page is loaded in your If statement - and not during postback when you need
it.
 
Back
Top