Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table

Status
Not open for further replies.

mary555

Programmer
Nov 9, 2005
185
CA
can anyone give me some ideas as to how you would dynamically create a table with asp,...a table on a form. I want to use a resultset to select all the records of a table, and then display them to the user on the web page. i was going to display the info in rows of a table, but i can't hardcode the number of rows or anything and so i need the table code only generated based on the resultset.
 
I notice that although you've been a member of Tek-Tips for some time, you haven't yet found any of the replies given to be valuable. If they haven't been valuable, read faq222-2244 to get some ideas on how to ask more effective questions. If they have, read the faq to see how to acknowledge them.

For this question, just open your table tag, get your recordset and loop through to EOF, generating a new <tr> for each record. Don't to clear up your recordset and connection objects when you're done. This should get you started
Code:
<table>

     <%
Set ObjCon = Server.CreateObject("ADODB.Connection")
With ObjCon
	.Provider = "MSDASQL"
	.ConnectionString = "DSN=mydsn;UID=;PWD=;"
	.open()
end with
StrSQL = "Select PicTitle, PicType From tblPics"
Set ObjRS = ObjCon.Execute(StrSQL)
Do While Not ObjRS.EOF
%>
<tr>
  <td ><%= ObjRS("PicTitle") %></td>
  <td ><%= ObjRS("PicType") %></td>
</tr>
<%
ObjRS.MoveNext
Loop
ObjRS.Close
set objRS = nothing
objCon.Close
set objCon = nothing
%>
</table>

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
what do you mean that I haven't found any answers to be valuable?????? Most of my questions have been answered and I've been completely satisfied with the answer.
 
unfortunately that doesn't work. i don't get any errors but the table just doesn't show up and theres lots of records in it
 
one sec, i may have figured out my problem...ill post the code in a minute
 
k this works
<html>
<!--#INCLUDE VIRTUAL="/connection.asp"-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Search</title>




</head>



<body>





<table>

<%


Dim RS
Set SQLStmt = Server.CreateObject("ADODB.Command")
SQLStmt.CommandText = "Select * from Out"
SQLStmt.CommandType = 1
Set SQLStmt.ActiveConnection = OBJdbConnection
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open SQLStmt



Do While Not RS.EOF
%>
<tr>
<td ><%= RS("Plant") %></td>
</tr>
<%
RS.MoveNext
Loop
RS.Close
set RS = nothing


%>
</table>





thanks for your help!
 
if johnwm has helped you solve your problem...acknowledge him...thats the least you can do...and this is what john was pointing out in his first post...

-DNG
 
sorry i didn't realize i had to say the person's name...i did say thanks for your help and i thought it was obvious who i was talking about.
 
lol

We are dancing around the issue because we aren't supposed to talk about purple stars and votes for TipMaster ...

So I hope I don't get "red flagged" for explaining that there is a link on the bottom of each posting that lets you mark a response as helpful and vote for someone as tipmaster and give a purple star.
star.gif
 
And the dance begins. ;)

Actually, I ran across a piece of code that allows you to quickly dump a database to a table.... let me see if I can find it....

Code:
<html>
<body><%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
%><table border="1" width="100%">
<%do until rs.EOF%>
   <tr>
   <%for each x in rs.Fields%>
      <td><%Response.Write(x.value)%></td>
   <%next
   rs.MoveNext%>
   </tr>
<%loop
rs.close
conn.close
%>
</table></body>
</html>


Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
oh well sorry i never ever saw that there was a link for that. where is it?
 
Each post has 3 links at the bottom of them. There is...

Thank JohnWM for this valuable post!
Inappropriate post? If so, Red Flag it!
Check out the FAQ area for this forum!

By clicking on the link, to thank someone, you are formally recognizing them as having a valuable post. This comes in handy for other people that may have a similar problem as you. If the thread has a purple star on it, there is a better chance that it contains a helpful response. This also makes the original poster feel a little better about donating their time to help other people. Really, though, think of it as an etiquette kind of thing.

You can also use the red-flag link to inform site management that someone has posted an offense message.

And of course, there's lots of valuable information in the frequently asked questions section for this forum. You should take a look at the FAQ's.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
There is quite a comprehensive note on the subject in the faq I originally pointed to faq222-2244

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top