Solved

Perform dynamic looping on datarow or datatable in vb aspx

Posted on 2013-12-16
6
397 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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 is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now