Loop Question
-
i need to loop some rows in my datagrid to add them and show the total. i am using:
Dim dr As DataRow Dim Amount As Double = 0 For Each dr As System.Data.DataRow _ In ds.Tables(0) dr = dr + ds.Tables(0).Rows.Item("Amount") Next Me.Text = ("My Balance $") & Amount.ToString
everything is fine except the underlined part. it keeps saying that it is a member of system.data.datatable which is not a collection type. does anyone know what i am doing wrong? Makniteasy -
i need to loop some rows in my datagrid to add them and show the total. i am using:
Dim dr As DataRow Dim Amount As Double = 0 For Each dr As System.Data.DataRow _ In ds.Tables(0) dr = dr + ds.Tables(0).Rows.Item("Amount") Next Me.Text = ("My Balance $") & Amount.ToString
everything is fine except the underlined part. it keeps saying that it is a member of system.data.datatable which is not a collection type. does anyone know what i am doing wrong? MakniteasyTables(0) is not a collection, it's a specific table.
... For each r as Datarow in ds.Tables(0).Rows ...
by the way your initial declaration of dr is reduntant since you are initializing it again within your for statement. just thought i'd mention it.
-jim
-
Tables(0) is not a collection, it's a specific table.
... For each r as Datarow in ds.Tables(0).Rows ...
by the way your initial declaration of dr is reduntant since you are initializing it again within your for statement. just thought i'd mention it.
-jim
thanks that fixed that problem but now i have another:
Dim Amount As Double = 0 For Each dr As DataRow In ds.Tables(0).Rows dr = dr + ds.Tables(0).item("Amount") Next Me.Text = ("My Balance $") & ("Amount").ToString
now this is underlined. i think im lost in the loop now.any more suggestions? Makniteasy -
thanks that fixed that problem but now i have another:
Dim Amount As Double = 0 For Each dr As DataRow In ds.Tables(0).Rows dr = dr + ds.Tables(0).item("Amount") Next Me.Text = ("My Balance $") & ("Amount").ToString
now this is underlined. i think im lost in the loop now.any more suggestions? Makniteasycan you give us an idea of exactly what it is you're trying to do? the code you've provided doesn't really make much sense. just a brief description should help.
-jim
-
thanks that fixed that problem but now i have another:
Dim Amount As Double = 0 For Each dr As DataRow In ds.Tables(0).Rows dr = dr + ds.Tables(0).item("Amount") Next Me.Text = ("My Balance $") & ("Amount").ToString
now this is underlined. i think im lost in the loop now.any more suggestions? MakniteasyYou're not adding the amounts. You're actually trying to add a Column to a DataRow. I think you're looking for:
Dim Amount As Double = 0
For Each dr As DataRow In ds.Tables(0).Rows
Amount += dr.Item("Amount")
Next
Me.Text = "My Balance $" & Amount.ToString()RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You're not adding the amounts. You're actually trying to add a Column to a DataRow. I think you're looking for:
Dim Amount As Double = 0
For Each dr As DataRow In ds.Tables(0).Rows
Amount += dr.Item("Amount")
Next
Me.Text = "My Balance $" & Amount.ToString()RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
thanks for the help. The help you provided was exactly what i needed. i was trying to get the amount column of a datagrid, for which the user enters the amount they paid, to show in the datagrid caption text when entered. I am going to post another question so that you wont have to keep to returning this one. thanks Makniteasy