【问题标题】:How to move to next row in dataset and display in hyperlink如何移动到数据集中的下一行并在超链接中显示
【发布时间】:2012-04-26 04:24:26
【问题描述】:

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

这是我的代码示例:

'填充数据集的代码

公共函数 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

【问题讨论】:

    标签: vb.net dataset row


    【解决方案1】:

    我不明白你为什么需要

      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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-06
      相关资源
      最近更新 更多