Solved

Perform dynamic looping on datarow or datatable in vb aspx

Posted on 2013-12-16
6
400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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