tags:

views:

84

answers:

1

I'm writing an email application that will be used to send HTML news articles to clients. I'm using a dataset to return the headlines to display to the client. When I loop through the dataset the the latest record is returned but latest headline link is not displayed. So the outputted HTML is the same headline everytime, which is the first record in the dataset. How do I move to the next record in the data set and get the outputted HTML to display the next/correct headline?

Here is a sample of my code:

'Code to populate dataset

Public Function GetHeadline(ByVal ArticleID As Integer) As DataSet

    Try
        Dim objConn As SqlConnection = New SqlConnection()
        objConn.ConnectionString = myConnectionString
        objConn.Open()

        ds = New DataSet
        ds.Clear()

        Dim sqlCommand As String = "SomeSql"

        Dim objCmd As SqlCommand = New SqlCommand(sqlCommand, objConn)

        Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter(objCmd)
        dataAdapter.Fill(ds)      

        Catch ex As Exception
        MsgBox(ex.ToString)
        GetHeadline = Nothing
    End Try

    Return ds

End Function

'Code to populate link

If GroupID = 4 Then
iLocation1 = HTMLbody.IndexOf("{!HeadlineID")

While iLocation1 > 0
 iLocation2 = HTMLbody.IndexOf("}", iLocation1)
 sHeadLineTag = HTMLbody.Substring(iLocation1 + 1, iLocation2 - iLocation1 - 1) 
 dtReport = clsGlobal.globalReportCatalog.GetHeadline2() 
 clsGlobal.globalReportCatalog.SetHeadlinePropertiesFromRow(dtReport.Rows(0))

 With clsGlobal.globalReportCatalog
  For i As Integer = 0 To dtReport.Rows.Count
   If i < dtReport.Rows.Count - 1 Then
    i = i + 1
   End If

   Dim ID As Integer = dtReport.Rows(i)("ArticleID")

   sHyperTag = "<a href=""" & "http://www.myweb.com/somedirectory/Login.aspx" & .HeadlineMarketingLink & """>" & .HeadlineReportName & " - " & .HeadlineTitle & "</a>"
   sHeadlineDescription = .HeadlineDescription   

   HTMLbody = HTMLbody.Replace("{!Report.Description}", sHeadlineDescription)

  Next
 End With
A: 

I don't see why you need

  For i As Integer = 0 To dtReport.Rows.Count
   If i < dtReport.Rows.Count - 1 Then
    i = i + 1
   End If

Can't you use

Dim ID As Integer = dtReport.Rows(dtReport.Rows.Count - 1)("ArticleID")

or was there supposed to be a row movenext in the loop you forgot?

Beth