?
Solved

VB WinForm: No Row at Position 0

Posted on 2007-07-30
2
Medium Priority
?
240 Views
Last Modified: 2013-11-26
I am authoring a VB.NET application, using VS 2003,  which builds an html string based on records from a SQL table, then spins through the record set, acceses records from a child table, appends the html string, spins through that table's child table, appends the html string, then goes to the next parent, and so forth. In other words, I have a nested record loop...going through three sets of records.  The final output is a formatted block of html code that will be pasted into a web page via a content editor. There are reasons for this approach that I won't go into here. When I execute the code, it goes all the way through the first record (parent, child and grandchild), and then gives me  an error "There is no row at position 1."

Following is the code for this routine:

    Private Sub btnHTML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHTML.Click
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim z As Integer = 0

        Dim strCampaignBlock As String
        Dim strPromoBlock As String
        Dim strLimitBlock As String

        Dim strImagePath As String
        Dim strPromoDescription As String

        Dim HTMLTableHeader As String = "<html><table border=""0"" cellspacing=""0"" cellpadding=""0"" width=""385""><tr>"
        Dim HTMLTableFooter As String = "</table>"
        Dim strListEnd As String = "</ul>"

        Dim dtCampaigns As New DataTable
        Dim dtPromos As New DataTable
        Dim dtLimits As New DataTable

        Dim CampaignRow As DataRow
        Dim PromoRow As DataRow
        Dim LimitRow As DataRow

        dtCampaigns = DA.RunSPGetDS("SelectHTMLCampaigns").Tables("HTMLCampaigns")

        For Each CampaignRow In dtCampaigns.Rows
            strCampaignBlock = dtCampaigns.Rows(x).Item("Header1") + dtCampaigns.Rows(x).Item("Header2")

            dtPromos = DA.RunSPGetDS("SelectPromosHTML", _
                DA.CreateParam("@CampaignID", dtCampaigns.Rows(x).Item("MCCampaignID"))).Tables("PromosHTML")

            x = x + 1

            For Each PromoRow In dtPromos.Rows
                If dtPromos.Rows.Count >= 1 Then
                    strPromoBlock = dtPromos.Rows(y).Item("FormattedPromo")

                    dtLimits = DA.RunSPGetDS("SelectHTMLLimits", DA.CreateParam("@PromoID", dtPromos.Rows(y).Item("PromoID"))).Tables("HTMLLimits")

                    If dtLimits.Rows.Count >= 1 Then
                        For Each LimitRow In dtLimits.Rows
                            strLimitBlock = strLimitBlock + dtLimits.Rows(z).Item("FormattedLimit")
                            z = z + 1
                            MessageBox.Show(strLimitBlock, "in limit loop")
                        Next LimitRow
                    End If
                    strPromoBlock = strPromoBlock + strLimitBlock
                    y = y + 1
                    strLimitBlock = ""
                End If

                strCampaignBlock = strCampaignBlock + strPromoBlock + strListEnd

            Next PromoRow

            Debug.WriteLine(HTMLTableHeader + strCampaignBlock _
                + HTMLTableFooter)
            MessageBox.Show("waiting")
        Next CampaignRow
        'Output a text file with the complete string
    End Sub

DA.xxxx are calls to a data access class which handles the ADO...in this case getting the data sets by running a stored procedure, with parameters passed by the class.
0
Comment
Question by:macecase
2 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 19593102
Hi,

whats the full error message reported?

thx
0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 19593638
You are not resetting y to 0 on each fresh run through the outer loop or z to 0 on each run through the inner loop.

Roger
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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