|
||||||||||||||||||||
Trouble adding rows to DataTable : Error = System.IndexOutOfRangeExceptio
|
Author | Message |
---|---|
![]() Hello everyone, I have a strange problem. It's hard to explain so please bare with me. I have 2 generic datatables produced in a different page. I only need to two columns from these datatables so I remove the other 12 columns from each datatable. So the result is I have 2 independant datatables that bind to two independant listboxes Now upon a button click I try to add the selected row or item (from System.IndexOutOfRangeException: Cannot find column 2. Now here is some code to clarify (hopefully): Private Sub Page_Load(ByVal sender As System.Object, ByVal e As dvIns = New DataView(dt_ins) With clbInsuredList dt_rem = New DataTable("INS_REMOVED") dvRem = New DataView(dt_rem) With clbRemovededList Private Sub btnPut_Click(ByVal sender As System.Object, ByVal e As For Each dc In Session("dt_local_rem").Columns I really hope this is an easy problem to fix because my computer is I even response.write'd Session("dt_local_rem").Columns.Count If I am just being dumb, please be gentle :) Any help would be greatly appreciated! Ryan |
|
Mon, 19 Sep 2005 07:18:21 GMT | |
![]() |
|
![]() Perhaps your column collection is zero based. Therefore you'd want to
reference columns zero and one (instead of one and two.) --
Quote: > Hello everyone, I have a strange problem. It's hard to explain so Session("dt_local_ins").Rows.find(clbInsuredList.Items(count).Value) > please bare with me. I have 2 generic datatables produced in a > different page. I only need to two columns from these datatables so I > remove the other 12 columns from each datatable. So the result is I > have 2 independant datatables that bind to two independant listboxes > Now upon a button click I try to add the selected row or item (from > System.IndexOutOfRangeException: Cannot find column 2. > Now here is some code to clarify (hopefully): > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > dvIns = New DataView(dt_ins) > With clbInsuredList > dt_rem = New DataTable("INS_REMOVED") > dvRem = New DataView(dt_rem) > With clbRemovededList > Private Sub btnPut_Click(ByVal sender As System.Object, ByVal e As > For Each dc In Session("dt_local_rem").Columns Quote: > ' deletes row DataView(Session("dt_local_rem").Tables("FHC_ADM.INS_REMOVED")) > dr.Delete() > ' removes item from list, this is so > ' we don't have to rebind, probably faster > clbInsuredList.Items.Remove(clbInsuredList.Items(count)) > Else > count += 1 > End If > Loop > ' rebind removed list > dvRem = New Quote: > dvRem.Sort() = "NAME_ID" > With clbRemovededList > .DataSource = dvRem > .DataTextField = "NAME_ID" > .DataValueField = "REG_ID_PLAN" > .DataBind() > End With > Catch ex As Exception > Response.Write(ex) > End Try > End Sub > I really hope this is an easy problem to fix because my computer is > I even response.write'd Session("dt_local_rem").Columns.Count > If I am just being dumb, please be gentle :) > Any help would be greatly appreciated! > Ryan |
|
Mon, 19 Sep 2005 07:21:56 GMT | |
Page 1 of 1 |
[ 2 post ] |