Solved

Perform dynamic looping on datarow or datatable in vb aspx

Posted on 2013-12-16
6
403 Views
Last Modified: 2013-12-18
I am converting a coldfusion page to .NET.  I am trying to figure out how to do a loop based off a listing of "srps" from date range selected. The table is named onesrp. I can't hard-code the "select value because the "srp fields" listing can change,not static.
I figured I also need a for each or some kind of for 1 to array.length looping to then pull the data to the output.  I have attached code. and view of original graph (example) and current output in .NET
looping-in-vb-NET.docx
0
Comment
Question by:mahpog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 500 total points
ID: 39723575
hi

after you get your datatable from database you can loop through it

dim dt as datatable=GetMyRowsFromDB()

for i as integer =0 to dt.rows.count-1

        xmlData.Append("<dataset seriesName='" & dt.rows(i)("output_srp") & "' >")
....etc
next
0
 

Author Comment

by:mahpog
ID: 39724181
I appreciate the help. I added your code as follows so far:

        Dim dt As DataTable = ds.Tables("Onesrp")

        For i As Integer = 0 To dt.Rows.Count - 1

            xmlData.Append("<dataset seriesName='" & dt.Rows(i)("srp_no") & "' >")

                 For i2 As Integer = 0 To dt.Rows.Count - 1

                  xmlData.Append("<set value='" & dt.Rows(i)("cntsrp") & "' />")

            Next

            xmlData.Append("</dataset>")

        Next
I want the "srp no" displayed once in the header for each 12 rows of data returns, and I graph the 12 counts for the 12 month period selected.  - farther than I have been but not right yet. (attached copy of current output with the code used above.
looping2-in-vb-NET.docx
0
 

Author Comment

by:mahpog
ID: 39724227
I made following adjustment and got header in graph correct, but missing data for all 12 months appears, i got one month of data correct. (attached graph views - original in Coldfusion,and .NET)

       Dim dt As DataTable = ds.Tables("Onesrp")

        For i As Integer = 0 To dt.Rows.Count - 1 Step 12

            xmlData.Append("<dataset seriesName='" & dt.Rows(i)("srp_no") & "' >")

            'For i As Integer = 0 To dt.Rows.Count - 1

            xmlData.Append("<set value='" & dt.Rows(i)("cntsrp") & "' />")

            'Next

            xmlData.Append("</dataset>")

        Next
looping3-goal-vs-curent-view-.docx
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:mahpog
ID: 39724351
latest code displays with same data across the months for the "srps".


        Dim dt As DataTable = ds.Tables("Onesrp")

        For i As Integer = 0 To dt.Rows.Count - 1 Step 12

            xmlData.Append("<dataset seriesName='" & dt.Rows(i)("srp_no") & "' >")

            For i2 As Integer = 0 To dt.Rows.Count - 1
                xmlData.Append("<set value='" & dt.Rows(i)("cntsrp") & "' />")

            Next

            xmlData.Append("</dataset>")
        Next
looping4-goal-vs-curent-view-.docx
0
 

Author Comment

by:mahpog
ID: 39727078
Final code:
        Dim dt As DataTable = ds.Tables("Onesrp")
        Dim index As Integer = 0

        For i As Integer = 0 To dt.Rows.Count - 1 Step 12

            xmlData.Append("<dataset seriesName='" & dt.Rows(i)("srp_no") & "' >")

            For i2 As Integer = index To dt.Rows.Count - 1

                xmlData.Append("<set value='" & dt.Rows(i2)("cntsrp") & "' />")
            Next
            xmlData.Append("</dataset>")

            index = index + 12

        Next
0
 

Author Closing Comment

by:mahpog
ID: 39727098
gave me food for thought and finally got graph correct.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question