Solved

Perform dynamic looping on datarow or datatable in vb aspx

Posted on 2013-12-16
6
399 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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