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

发布于 2024-09-16 04:01:55 字数 1844 浏览 2 评论 0原文

我正在编写一个电子邮件应用程序,用于向客户发送 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-09-23 04:01:55

我不明白你为什么需要

  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 吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文