如何移动到数据集中的下一行并显示在超链接中

时间:2010-08-23 21:36:25

标签: vb.net dataset row

我正在编写一个电子邮件应用程序,用于向客户发送HTML新闻文章。 我正在使用数据集返回标题以显示给客户端。当我遍历数据集时,将返回最新记录,但不会显示最新的标题链接。因此输出的HTML每次都是相同的标题,这是数据集中的第一条记录。如何移动到数据集中的下一条记录并获取输出的HTML以显示下一个/正确的标题?

以下是我的代码示例:

'填充数据集的代码

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

'填充链接的代码

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

1 个答案:

答案 0 :(得分:0)

我不明白你为什么需要

  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(dtReport.Rows.Count - 1)("ArticleID")

或者在你忘记的循环中应该有一行movenext吗?