Jump to content
  • Advertisement
Sign in to follow this  
boolean

[web] Fill table with content on ASP page

This topic is 5404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this is a simple question, and everyone is preparing the [google] icon, but I cant seem to find anything that I can understand on the information superhighway. I am still quite new to ASP [smile] Basically, I have a table here that I am currently updating manually with content from the DB. I am trying to figure out how I can grab the fields I need from the DB and autofill the table with the content. At the moment I can only seem to figure out how to get one line to print. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
You want to do something like this:


<%
set rsRequests= conSR.Execute("SELECT * FROM [Master Maintenance] WHERE Something Here")
while NOT rsRequests.EOF
%>
<TR>
<TD align=left width=250><%= rsRequests("Title") %></TD>
<TD align=right width=100><%= rsRequests("Date") %></TD>
<TD align=right width=100><%= rsRequests("Complete") %></TD>
</TR>
<%
rsRequests.movenext
wend
%>


Share this post


Link to post
Share on other sites
Quote:
Original post by jswidorski
You want to do something like this:

<CODE>
<%
set rsRequests= conSR.Execute("SELECT * FROM [Master Maintenance] WHERE Something Here")
while NOT rsRequests.EOF
%>
<TD align=left width=250><%= rsRequests("Title") %></TD>
<TD align=right width=100><%= rsRequests("Request Date") %></TD>
<TD align=right width=100><%= rsRequests("Complete Date") %></TD>
</TR>
<%
rsRequests.movenext
wend
%>
</CODE>

How do I put this in a code block?


you want [ source ] tags

Share this post


Link to post
Share on other sites
boolean, what's your db? Here's an example how to do it in SQL server with vb:

I like to build the entire table with server side code, rather than jswidorski's method, but either will work fine. So in your html you've got something like:

<body>
<form>
----stuff
<%CreateTable%> ----the place where you want your table
</form>
</body>

Then in your code behind:

Public Sub CreateTable()
Dim sHTML As String
sHTML = "<TABLE STYLE=""Z-INDEX: 102; LEFT: 0px; POSITION: relative; TOP: 0px"" CELLSPACING=""0""" _
& "CELLPADDING=""1"" WIDTH=""300"" BORDER=""1"" bordercolor=""black"">"

Dim SQLConn As New SqlConnection
SQLConn.ConnectionString = ConfigurationSettings.AppSettings("ConnString")

Try
SQLConn.Open()

Dim objDA As New SqlDataAdapter
Dim objDataReader As SqlDataReader
Dim Cmd As New SqlCommand("pGetCustomers", SQLConn)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.Add(New SqlParameter("@AppID", 1))

objDataReader = Cmd.ExecuteReader

sHTML += "<TR><TD colspan=""3"">Customer Information</TD></TR>"
While objDataReader.Read

sHTML += "<TR><TD>" & objDataReader.Item("vcName") & "</TD>"
sHTML += "<TD>" & objDataReader.Item("vcAddress") & "</TD>"
sHTML += "<TD>" & objDataReader.Item("iPhoneNumber") & "</TD></TR>"

End While
objDataReader.Close()
objDataReader = Nothing

sHTML += "</TABLE>"

Response.Write(sHTML)

Cmd.Dispose()
objDA.Dispose()
Catch ex As Exception
Throw New Exception("Error getting customer information.")
Finally
SQLConn.Dispose()
End Try
End Sub




The ConfigurationSettings.AppSettings("ConnString") line just reads the connection string I set up in web.config (which is a nice way to do things so that you don't have to write out the whole string each time. You can use either a DataReader or DataAdapter depeding on what you want to do with the data.

Oh yeah, the Sub or Function has to be public for you to be able to call it like this.

Share this post


Link to post
Share on other sites
Quote:
Original post by evolutional
Zul, that looks suspiciously like .NET code [wink]


You got me :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!