Solved

Perform dynamic looping on datarow or datatable in vb aspx

Posted on 2013-12-16
6
398 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript error 1 51
getting id from database 5 36
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 30
Pagebreak issue while printing the aspx page 3 10
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
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 …

948 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

18 Experts available now in Live!

Get 1:1 Help Now