0

目前,我正在寻找一种解决方案,让我的数据在后面的代码中循环?

它实际上是一个从数据库中查询的包含标题和内容的公告列表。

cmdDa = New SqlDataAdapter("SELECT * FROM announcement ORDER BY announcement_PostDT DESC", conn)
ds = New DataSet()

cmdDa.Fill(ds, "announcement")
Dim total_rows_count As Integer = ds.Tables("announcement").Rows.Count - 1

For i = 0 To total_rows_count

   Dim title As String = ds.Tables("announcement").Rows(i).Item("announcement_Title")

   'How do I going to make it display on a label and keeps it loop?
   lbl_announcement_title.Text += title
   'This is not the thing I expect, what I expect is to make it show nicely, like 
   'the next loop will automatically goes to the next line.
Next

我应该把它放到面板、列表视图或任何东西中并循环吗?急需帮助!

4

1 回答 1

0

要完成您想要的代码可能是这样的:

cmdDa = New SqlDataAdapter("SELECT * FROM announcement ORDER BY announcement_PostDT DESC, announcement_Title ASC", conn)
ds = New DataSet()

cmdDa.Fill(ds, "announcement")
Dim total_rows_count As Integer = ds.Tables("announcement").Rows.Count - 1
Dim title As String = String.Empty
Dim content As String = String.Empty
Dim itemText As String = String.Empty
For i = 0 To total_rows_count
   title = ds.Tables("announcement").Rows(i).Item("announcement_Title")
   content = ds.Tables("announcement").Rows(i).Item("announcement_Content")

  itemText = "Title: "+ title + " Content: "+ content
   lbl_announcement_title.Text += itemText + "</br>
Next
于 2012-05-19T05:17:47.410 回答