目前,我正在寻找一种解决方案,使我的数据循环在代码背后?
它实际上是一个公告列表,从数据库中查询包含标题和内容。
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
我应该将它放入面板,列表视图或任何东西并循环它吗?急需帮助!
答案 0 :(得分: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