-
Using asp, how would I set the array to display every row, but only columns 1, 3, and 6? I want the database to store all fields, but the display page should show only these few fields. Thanks for any help.
Here is my code I already have, it shows all fields which isn't what I need. Please help.
Code:
<%
Dim cnn
Dim rst
Dim connectString
set cnn = Server.CreateObject ("ADODB.Connection")
set rst = Server.CreateObject ("ADODB.Recordset")
ConnectString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\shared webs\art\new1\mdb\speed.mdb"
cnn.open connectString
rst.open "speed", cnn, 2, 2
%>
<Table Border="1" width="100%">
<tr bgcolor="#C0C0C0">
<%
if rst.EOF AND rst.BOF then
Response.Write ( "No Records found")
else
'output field names
For intFieldCounter = 0 To (rst.Fields.Count) - 1
Response.Write( "<TH>" & rst.Fields.Item(intFieldCounter).Name )
Next
Response.Write ( "</TR>" )
'output records
Do Until rst.EOF
Response.Write( "<TR>" )
for intFieldCounter = 0 to (rst.Fields.Count) - 1
if rst.Fields.Item(intFieldCounter).Name = "DonorID" then
Response.Write( "<TD> <A HREF=http://" & strServerName & "/dacm/content/donorTests.asp?DonorID=" & rst(intFieldCounter) & ">" & rst(intFieldCounter) & " </a> </TD>" )
else
Response.Write( "<TD>" & rst(intFieldCounter) & "</TD>" )
end if
Next
rst.MoveNext
Response.Write( "</TR>" )
Loop
Response.Write( "</Table>" )
rst.Close
cnn.Close
set cnn = Nothing
End if
%>
-
Hi artsapimp
To do what you ask, open your recordset using a SQL string.
Replace
rst.open "speed", cnn, 2, 2
With
rst.open "SELECT column1, column3, column6 From speed", cnn, 2, 2
repacing columnx with the names of your columns from the database
Hope this helps
Ian
-
Perfect, thank you very much.
How would I make the first column (ID) be a link to another page that shows all fields for the customer?
-
In your for loop do an If statement to see if the field number is the id column, and if it is put in an A tag but make the href = MYnewpage.asp?id=<% = rst(intFieldCounter) %>
Then in the new page use myid = request.querystring("id") to get the id.
Then when you open the recordset use "SELECT * FROM speed WHERE idcolumn = " & myid
if you Need any more help reply back
Ian
-
I got this error:
'800a0cc1'
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.
This is how I wrote the code, I'm sure it's wrong
[code]
If rst.Fields.Item(intFieldCounter).Name = "ID" Then
%>
<A href=edit.asp?id=<% = rst(intFieldCounter) %>><%= rst(intFieldCounter) %></A>
<%
End If
-
I cant see any error's
Which line are you getting it.
On the if statement or on the link line.
Ian
-
ADODB.Fields error '800a0cc1'
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.
/arthur/new1/mdb/test.asp, line 38
line 38:
Code:
If rst.Fields.Item(intFieldCounter).Name = "ID" Then
This is the whole code as of right now if that helps
Code:
<%
Dim cnn
Dim rst
Dim connectString
set cnn = Server.CreateObject ("ADODB.Connection")
set rst = Server.CreateObject ("ADODB.Recordset")
ConnectString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\shared webs\art\new1\mdb\speed.mdb"
cnn.open connectString
rst.open "SELECT ID, Location, Phone, ProvisionedSpeed, ActualSpeed, Status, NDCAgent From NDC", cnn, 2, 2
%>
<Table Border="1" width="100%">
<tr bgcolor="#C0C0C0">
<%
'output field names
For intFieldCounter = 0 To (rst.Fields.Count) - 1
Response.Write( "<TH>" & rst.Fields.Item(intFieldCounter).Name )
Next
Response.Write ( "</TR>" )
'output records
Do Until rst.EOF
Response.Write( "<TR>" )
for intFieldCounter = 0 to (rst.Fields.Count) - 1
Response.Write( "<TD>" & rst(intFieldCounter) & "</TD>" )
Next
rst.MoveNext
If rst.Fields.Item(intFieldCounter).Name = "ID" Then
%>
<A href=edit.asp?id=<% = rst(intFieldCounter) %>><%= rst(intFieldCounter) %></A>
<%
End If
Response.Write( "</TR>" )
Loop
Response.Write( "</Table>" )
rst.Close
cnn.Close
set cnn = Nothing
%>
-
Hi there again
still can't see what your problem if you replace the for loop with this
Code:
for intFieldCounter = 0 to (rst.Fields.Count) - 1
If intFieldCounter = 0 Then
%>
<TD><A href="edit.asp?id=<% = rst(intFieldCounter) %>"><%= rst(intFieldCounter) %></A></TD>
<%
else
Response.Write( "<TD>" & rst(intFieldCounter) & "</TD>" )
End If
Next
rst.MoveNext
You will get the desired affect
Ian