Link to home
Start Free TrialLog in
Avatar of Peter Nordberg
Peter NordbergFlag for Sweden

asked on

Loop through dataset

Hi,

I'm trying to go through a dataset row by row to do some changes for each row. I tried this code using a treeview checkbox click to activate the procedure:
----------------------------------------------------------------------------
Protected Sub RadTreeView2_NodeCheck(ByVal o As Object, ByVal e As Telerik.WebControls.RadTreeNodeEventArgs) Handles RadTreeView2.NodeCheck
        If e.NodeChecked.Value > 1 Then

            Dim cImage As New imagesDL

            Dim i As Integer

            For Each i In cImage.GetImagesByNodeID(e.NodeChecked.Value)

                            Label1.Text = cImage.imageID


            Next

                 End If

        Response.Redirect(Request.Url.LocalPath)

    End Sub

--------------------------------------------------------------------------

When I do this I get this error:

Server Error in '/ArkenImages' Application.
--------------------------------------------------------------------------------

Unable to cast object of type 'System.Data.DataSet' to type 'System.Collections.IEnumerable'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.DataSet' to type 'System.Collections.IEnumerable'.

Source Error:


Line 96:             Dim i As Integer
Line 97:
Line 98:             For Each i In cImage.GetImagesByNodeID(e.NodeChecked.Value)
Line 99:
Line 100:                'ILoad1.Value = WebImage.Load(Server.MapPath("Uploads/images"), cImage.imageID)
 
--------------------------------------------------------------------------------

Grateful to get help in how to be able to go through each row in the dataset to perform some actions.

Peter
ASKER CERTIFIED SOLUTION
Avatar of craskin
craskin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peter Nordberg

ASKER

Hi, thanks for answer!

I tried this and it didn't complain:

 Dim cImage As New imagesDL

            Dim row As DataRow
            Dim ds As DataSet = cImage.GetImagesByNodeID(e.NodeChecked.Value)

            For Each row In ds.Tables(0).Rows

                'ILoad1.Value = WebImage.Load(Server.MapPath("Uploads/images"), cImage.imageID)
                'ILoad1.Value.Delete()
                Label1.Text = cImage.imageID
                'Response.Write(row.Item)


            Next
-------------------------------------------------------------------
But how would I get the id for each row?

Peter
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial