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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data in DB table cell not displaying in asp page table cell

Status
Not open for further replies.

PSchubert

Technical User
Jun 6, 2006
50
0
0
AU
Hi Tech!

Thanks in advance for your help. Tek-Tips has always been extremely helpful when I'm expreriencing stumpage.

I have an asp page that connects to a database. Everything works great except for this one table cell on the page.

In the database is a table, tblTravelHistory:

tblTravelHistory_hsj2pd.jpg


(there are other records in the table, but that's not relevant.)

Here is the output to the table on the asp page:

TravelHistory_tlud9t.jpg


As you can see, the Notes cell is empty, where the database table shows "initial entry" in the field mfldNotes. This is the problem.

Here is the relevant code for the page:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]

<html>

   <head>

      <style type="text/css">

	 table.better {
            border-collapse: collapse;
            padding: 2px;
            }

	 table.better, th.better {
            border-style: solid;
            border-width: 1px;
            border-color: #002B53;
            }

	 tr.better:hover {background-color: #ccddff;}

	 th.better {
            background-color: #2B5BA2;
            font-family: arial;
            font-size: small;
            color: white;
            padding: 4px;
            }

	 td.better {
            border-style: solid;
            border-width: 1px;
            border-color: #002B53;
            font-family: arial;
            font-size: small;
            font-weight: bold;
	    text-align: left;
            padding: 4px;
            }

	 td.better0a {
            border-style: solid;
            border-width: 1px;
            border-color: #002B53;
            font-family: arial;
            font-size: small;
            font-weight: bold;
	    text-align: center;
	    color: #009900;
            padding: 4px;
            }

	 td.better0b {
            border-style: solid;
            border-width: 1px;
            border-color: #002B53;
            font-family: arial;
            font-size: small;
            font-weight: bold;
	    text-align: center;
	    color: #FF0000;
            padding: 4px;
            }

      </style>

<%

   Dim conn			
   Dim rs
   Dim strSQL
   Dim strConnection
   Dim idxItems
   Dim i
   Dim InOut
   Dim temp

   Set conn = Server.CreateObject("ADODB.Connection")
   Set rs = Server.CreateObject("ADODB.Recordset")

   idxItems = rs("idxItems")

   InOut = array("IN", "OUT")

   Response.Write("<title>" & Session("name") & " Collection</title></head><body style='margin-left: 20px;'>")

   conn.Open strConnection

   strSQL = "SELECT ynfldInOut, dfldDate, mfldNotes, tfldReference FROM tblTravelHistory " & "WHERE nfldidxItems=" & idxItems & ";"

   Set rs = conn.Execute (strSQL)

   Response.Write("<table class='better'><caption style='font-family: arial; font-size: small; font-weight: bold; text-decoration: underline;'>Travel History</caption>" & _
      "<tr><th class='better'>IN / OUT</th><th class='better'>Date</th><th class='better'>Notes</th><th class='better'>Reference</th></tr>")

   rs.MoveFirst

   Do While Not rs.EOF
      Response.Write ("<tr class='better'>")

      For i = 0 to rs.Fields.Count - 1

      temp = rs.Fields(i)

      If i = 0 Then
         If temp + 1 = 0 Then 
            temp = "0a'>" & InOut(temp + 1)
         Else
            If temp + 1 = 1 Then 
               temp = "0b'>" & InOut(temp + 1)
            End If
         End If
      Else
         temp = "'>" & rs.Fields(i)
      End If

      Response.Write("<td class='better" & temp & "</td>")
      Next

      Response.write("</tr>")

      rs.MoveNext
   Loop

   Response.Write("</table>")
	
   rs.Close

   Response.Write("</body></html>")

   set rs = Nothing
   conn.Close
   set conn = Nothing
   Response.End
%>

(there's more to the page, but as it all works great I haven't included it.)

I can't figure it out, especially as I have five other tables on the page that display perfectly with basically the same code, EXCEPT that four of them don't use the InOut array. Why would this one cowardly field and/or table cell stubbornly refuse to show itself?

I humbly turn the problem over to you Tek-Tippers, who have proven yourselves in the past to be much smarter than I.
 
I don't see any errors yet in the code that creates the HTML table that would cause "notes" to not show.

But I do see one odd thing in the code below:
Code:
Set rs = Server.CreateObject("ADODB.Recordset")
[highlight #73D216]idxItems = rs("idxItems")[/highlight]

InOut = array("IN", "OUT")
Response.Write("<title>" & Session("name") & " Collection</title></head><body style='margin-left: 20px;'>")
conn.Open strConnection

[highlight #73D216]strSQL = "SELECT ynfldInOut, dfldDate, mfldNotes, tfldReference FROM tblTravelHistory " & "WHERE nfldidxItems=" & idxItems & ";"[/highlight]
Set rs = conn.Execute (strSQL)

The first line defines a recordset, but before you have even opened it, in the second line you are assigning idxItems to a value from it (rs("idxItems")), which is a value of a recordset that is not even open??? Yet you use this value a few lines down to actually open the recordset. I would expect an error to have been generated at some point, so I'm surprised the code even gets past this point.
 
Oops! Well spotted, guitarzan.

That was just an error from my clumsy copy and pasting. The variable idxItems holds a value from a previously opened recordset that filters the results of the SQL statement. As I didn't paste the code for the entire page (it's too onerous), I just pasted that line in the wrong place.

I really appreciate you looking at my problem.

 
Then I dont see a problem. Maybe add this at the end of your loop
Code:
Next
Response.write("</tr>")
[highlight #FCE94F]s = s & "Note: " & rs("mfldNotes") & "<br>"[/highlight]
rs.MoveNext

and then add "response.write s" at the end, so see if any of the records have values in the Notes field. If so, maybe its a css format issue
 
If you load the page and then view source to get the HTML output that might give you some clues. Are you able to paste the HTML output here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top