Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Re: Response.Write


Message #1 by "CLINTON PARSLEY" <cparsley@m...> on Mon, 08 Apr 2002 08:12:50 -0700
I used this with nwind.mdb provided by Microsoft
with your OS...Give it a shot and play around with
it, change it as you see fit. Be careful about wrapping

hth,
Clint

Sub DisplayTable(sSql)
Dim strSql,intCols,intRows,objConn,objRS,x,i,intRec
strSql = sSql
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.Open"Provider=Microsoft.Jet.OLEDB.4.0;" & _
	"Persist Security Info=False;" & _
	"Data Source=" & Server.Mappath("nwind.mdb")

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.open strSql, objConn,1,1,1
intRows = objRS.RecordCount
intCols = objRS.Fields.count

Response.Write(intRows & " Records Returned")
Response.Write("<table width=""600"" cellPadding=""3"" & _ cellSpacing=""0"" 
border=""0"" style=""border:1px" & _
" solid #000000;"">")
Response.Write("<tr>")

If Not objRS.EOF Then

For x = 0 to objRS.Fields.Count-1
Response.Write("<th width=""120"" style=""text-align:left;"">" & _
objRS.Fields(x).Name  & "</th>")
Next

Response.Write("</tr>")

For intRec = 1 To objRS.RecordCount

If Not objRS.EOF Then

If intRec mod 2 Then
Response.Write("<tr style='font-size:8pt;'>")
Else
Response.Write("<tr style='font-size:8pt;background:#e4f7e4;'>")
End If

For i= 0 to objRS.Fields.Count-1
Response.Write("<td nowrap style='border-bottom:1px solid" & _
" #3f8640;'>&nbsp;" & objRS.Fields(i).Value & "</td>")
Next

Response.Write("</tr>")
objRS.MoveNext
End If
Next

Else
Response.Write("<td colspan=""" & intCols & """ style=""text-" & _
" align:left;"">There are no records to display</td>")
End If

' Clean up
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
End Sub


>From: IT@g...
>Reply-To: "ASP Databases" <asp_databases@p...>
>To: "ASP Databases" <asp_databases@p...>
>Subject: [asp_databases] Response.Write
>Date: Mon, 8 Apr 2002 15:14:30
>
>Hi, I have just started out programming in ASP.
>
>I have a table that can potentially contain many fields.
>
>I want my ASP page to only display the information if there is some data
>in there.
>
>For example in my Access database there are about 20 fields that can be
>used in my table.  But I only want it to display the results if the fields
>contain a value.
>
>Is there a function that will enable my asp template page to not
>Response.Write if the field is empty?
>
>Or maybe a function that will dynamically display all of the fields that
>contain data listed within a table and ignore the fields with no data?
>
>What I don't want is to have to hard code the headings of a table only for
>it to be blank if there is no data in some of the fields.
>
>I would be very grateful if someone out there could help.
>
>Thanks in advance.




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Message #2 by imran.saleem@b... on Mon, 8 Apr 2002 15:10:20 +0100
IF recordset("field_name") <> "" THEN
	Response.write recordset("field_name")
END IF

-----Original Message-----
From: IT@g... [mailto:IT@g...]
Sent: Monday, April 08, 2002 4:15 PM
To: ASP Databases
Subject: [asp_databases] Response.Write


Hi, I have just started out programming in ASP.

I have a table that can potentially contain many fields.

I want my ASP page to only display the information if there is some data 
in there.

For example in my Access database there are about 20 fields that can be 
used in my table.  But I only want it to display the results if the fields 
contain a value.

Is there a function that will enable my asp template page to not 
Response.Write if the field is empty?

Or maybe a function that will dynamically display all of the fields that 
contain data listed within a table and ignore the fields with no data?

What I don't want is to have to hard code the headings of a table only for 
it to be blank if there is no data in some of the fields.

I would be very grateful if someone out there could help.

Thanks in advance.
Message #3 by IT@g... on Wed, 10 Apr 2002 13:12:02
I'd just like to say thanks to everyone who replied to my message.

I have found the solution I was looking for in the following code:



IF IsNull (objRS("MyField")) THEN
Response.Write ("")
Else
Response.Write "<b>The Title of my Field</b> " & objRS("MyField")


All that I needed to use was the function IsNull.


Thanks again.





> Hi, I have just started out programming in ASP.

> I have a table that can potentially contain many fields.

> I want my ASP page to only display the information if there is some data 
i> n there.

> For example in my Access database there are about 20 fields that can be 
u> sed in my table.  But I only want it to display the results if the 
fields 
c> ontain a value.

> Is there a function that will enable my asp template page to not 
R> esponse.Write if the field is empty?

> Or maybe a function that will dynamically display all of the fields that 
c> ontain data listed within a table and ignore the fields with no data?

> What I don't want is to have to hard code the headings of a table only 
for 
i> t to be blank if there is no data in some of the fields.

> I would be very grateful if someone out there could help.

> Thanks in advance.
Message #4 by Marijn.Schops@p... on Mon, 8 Apr 2002 16:11:33 +0200
I think it's most easy if you first check if the recordset you get contains
any records, like this :

If rsExample.EOF Then
  Response.Write "No records returned"
Else
  Response.Write "<table>"
  ...
  Response.Write "</table>"
End If

----------------------------------------------------------------------------------

Marijn Schops
Software Engineer

Professional Interactive Media Centre
Wetenschapspark 5 - 3590 Diepenbeek - Belgium
Tel. +xx-xx-xx xx xx   Fax. +xx-xx-xx xx xx
Email : Marijn.Schops@p...


                                                                                                                     
                    IT@g...                                                                                  
                    les.org.uk             To:     "ASP Databases" <asp_databases@p...>                      
                                           cc:                                                                       
                    08/04/2002             Subject:     [asp_databases] Response.Write                               
                    17:14                                                                                            
                    Please respond                                                                                   
                    to "ASP                                                                                          
                    Databases"                                                                                       
                                                                                                                     
                                                                                                                     




Hi, I have just started out programming in ASP.

I have a table that can potentially contain many fields.

I want my ASP page to only display the information if there is some data
in there.

For example in my Access database there are about 20 fields that can be
used in my table.  But I only want it to display the results if the fields
contain a value.

Is there a function that will enable my asp template page to not
Response.Write if the field is empty?

Or maybe a function that will dynamically display all of the fields that
contain data listed within a table and ignore the fields with no data?

What I don't want is to have to hard code the headings of a table only for
it to be blank if there is no data in some of the fields.

I would be very grateful if someone out there could help.

Thanks in advance.




Message #5 by IT@g... on Mon, 8 Apr 2002 15:14:30
Hi, I have just started out programming in ASP.

I have a table that can potentially contain many fields.

I want my ASP page to only display the information if there is some data 
in there.

For example in my Access database there are about 20 fields that can be 
used in my table.  But I only want it to display the results if the fields 
contain a value.

Is there a function that will enable my asp template page to not 
Response.Write if the field is empty?

Or maybe a function that will dynamically display all of the fields that 
contain data listed within a table and ignore the fields with no data?

What I don't want is to have to hard code the headings of a table only for 
it to be blank if there is no data in some of the fields.

I would be very grateful if someone out there could help.

Thanks in advance.

  Return to Index