I have the following function that returns only the 1st row of data and puts it in a nice table. My knowledge in this area is limited in that I don’t know how to create the table to return multiple rows. Can you show me how to change this to return all rows, no matter how many there are? my sql select statement may return 0 rows or many rows.
thanks:
<System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()> _
Public Shared Function GetDynamicContent(contextKey As String) As String
Dim constr As String = "Data Source=my data source"
Dim query As String = "SELECT * FROM Details WHERE ItemID = " & contextKey
Dim da As New SqlDataAdapter(query, constr)
Dim table As New DataTable()
da.Fill(table)
Dim b As New StringBuilder()
b.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid; ")
b.Append("width:350px; font-size:10pt; font-family:Verdana;' cellspacing='0' cellpadding='3'>")
b.Append("<tr><td colspan='3' style='background-color:#336699; color:white;'>")
b.Append("<b>Budget Item Details</b>")
b.Append("</td></tr>")
b.Append("<tr><td style='width:80px;'><b>Detail</b></td>")
b.Append("<td style='width:80px;'><b>Amount</b></td>")
b.Append("<td><b>Date</b></td></tr>")
b.Append("<tr>")
b.Append("<td>$" & table.Rows(0)("Detail").ToString() & "</td>")
b.Append("<td>" & table.Rows(0)("Amount").ToString() & "</td>")
b.Append("<td>" & table.Rows(0)("DetailDate").ToString() & "</td>")
b.Append("</tr>")
b.Append("</table>")
Return b.ToString()
End Function
Try this. You need a
FORloop to create rows.