Solved

Trying to pull data from SQL database table: Microsoft VBScript runtime error '800a000d'

Posted on 2013-01-25
7
582 Views
Last Modified: 2013-01-25
I just added some address fields to a table for events listings on this page here and I've called them in, but it's giving me the following error:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'HTMLEncode'
/events.asp, line 125

I've created a test advert and it stored in the database so that's working, but I can't pull the data into the front end without it breaking the code.

Here's the code for the events listing pages with the bold bit being the additional fields I added and populated:

<!--#include virtual="/System/Startup_Public.asp"-->
<%
If Session("PublicFranchiseGID") = "" then
    Response.Redirect "/"
End if

	sLink = "/" & lcase(session("publicfranchisename")) & "/events/index.html"
	
	sym = "?"
	if len(""&request.querystring("evtd"))>0 then 
		sLink=sLink&sym&"evtd="&request.querystring("evtd")
		sym="&"
	end if
	if len(""&request.querystring("evtc"))>0 then 
		sLink=sLink&sym&"evtc="&request.querystring("evtc")
		sym="&"
	end if
	if len(""&request.querystring("evtsd"))>0 then 
		sLink=sLink&sym&"&evtsd="&request.querystring("evtsd")
		sym="&"
	end if
	
	if not sLink = request.ServerVariables("HTTP_X_REWRITE_URL") then
		response.status = "301 Moved Permanently"
		response.addheader "Location", "http://www.inside-guides.co.uk" & sLink
		response.end
	end if

EnsurePageIsBasicHTTP

startdate = date()
if len(""&getquery("evtsd"))>0 then
	if isdate(getquery("evtsd")) then
		startdate = getquery("evtsd")
	end if
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events, Essex, What's On in <%=server.HTMLEncode(Session("PublicFranchiseName"))%></title>
<meta name="Description" content="<%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events and What's On in <%=server.HTMLEncode(Session("PublicFranchiseName"))%>, Essex" />
<meta name="Keywords" content="<%=server.HTMLEncode(Session("PublicFranchiseName"))%> Events, What's On <%=server.HTMLEncode(Session("PublicFranchiseName"))%>, Things to do in <%=server.HTMLEncode(Session("PublicFranchiseName"))%>" />
<link rel="stylesheet" type="text/css" href="/css/hot-sneaks/jquery-ui-1.8.22.custom.css"/>
<!--#include virtual="/Assets/Templates/Public/Franchise/HeadCSS.asp"-->
<link rel="stylesheet" type="text/css" href="/css/EventList.css"/>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(e) {
        $('#datepicker').datepicker({
			dateFormat:'dd/mm/yy',
			defaultDate: '<%=startdate%>',
			onSelect: function(dateText, inst) { $('#evtsd').val(dateText); }
		});
			
    });
</script>
</head>
<body id="events">
<!--#include virtual="/Assets/Templates/Public/Franchise/Events.asp"-->
    <% 
	
	' default query, top 20 events on or after today
	limit = " TOP 30 "
	where = " AND (ca_enddate >= cast(GetDate() as date))"
	
	if len(""&getquery("evtsd")) >0 then
		if isdate(getquery("evtsd")) then
			sdate = year(getquery("evtsd")) & "-" & month(getquery("evtsd")) & "-" & day(getquery("evtsd"))
			where=""
			if left(getquery("evtd"),1) = "p" then
				'where = where & " AND (ca_startdate BETWEEN '"&sdate&"' AND DATEADD(day,"&cint(replace(request.querystring("evtd"),"p",""))&",'"&sdate&"')) "
				
				where = where & " AND (ca_startdate < DATEADD(day,"&cint(replace(request.querystring("evtd"),"p",""))&",'"&sdate&"') AND "&_ 
												" ca_enddate > '"&sdate&"') "
			else
				where = where & " AND (ca_startdate BETWEEN DATEADD(day,-"&cint(replace(request.querystring("evtd"),"m",""))&",'"&sdate&"') AND '"&sdate&"') "		
			end if
			limit = ""
		end if
	end if
	
	if len(""&getquery("evtc"))>0 then
		if isnumeric(getquery("evtc")) then
			where = where & " AND ca_category = "&cint(getquery("evtc"))
		end if
	end if
	
	sql = "SELECT "&limit&" *,dbo.RemoveNonAlphaCharacters(LTRIM(RTRIM(ca_title))) AS URL "&_ 
        "FROM CommunityArticles "&_ 
        "LEFT JOIN CommunityArticleCategories ON ca_category = cac_id "&_ 
        "WHERE ca_live = 1 AND ca_franchise = '{"&session("PublicFranchiseGID")&"}'	"&_ 
		where &_ 
		"ORDER BY ca_startdate ASC;"
		
    getrs rs,sql,""
	
	if rs.recordcount = 0 and len(""&limit)>0 then
		' no current events, fall back to archive listing
		sql = "SELECT TOP 20 *,dbo.RemoveNonAlphaCharacters(LTRIM(RTRIM(ca_title))) AS URL "&_ 
			"FROM CommunityArticles "&_ 
			"LEFT JOIN CommunityArticleCategories ON ca_category = cac_id "&_ 
			"WHERE ca_live = 1 AND ca_franchise = '{"&session("PublicFranchiseGID")&"}'	"&_ 
			"ORDER BY ca_startdate ASC;"
	end if
	
	if rs.recordcount > 0 then
    while not rs.eof 
    url = "/" & lcase(session("publicfranchisename")) & "/events/" & year(rs("ca_startdate")) & "/" & monthname(month(rs("ca_startdate"))) & "/" & server.URLEncode(rs("URL")) & ".html"
    %>
        <div class="event">
            <table width="100%" border="1">
              <tr>
                <td width="160" valign="top">
                    <% if len(""&rs("ca_thumbnail"))>0 then %>
                    <div class="event_image"><a href="<%=url%>"><img alt="<%=Session("PublicFranchiseName")%> events" src="/includes/tn.asp?src=/LiveStorage/Uploads/image/CommunityArticles/<%=server.URLEncode(""&rs("ca_thumbnail"))%>" 
                        alt="<%=server.HTMLEncode(""&rs("ca_title"))%>" /></a></div>
                    <% end if %>
                </td>
                <td valign="top">
                    <h3><% if len(""&rs("cac_image")) > 0 then %><img alt="<%=Session("PublicFranchiseName")%> event category" src="/Assets/Images/EventCategories/<%=server.URLEncode(""&rs("cac_image"))%>" alt="<%=server.HTMLEncode(""&rs("cac_category"))%>" class="category" /><% end if %><a href="<%=url%>"><%=server.HTMLEncode(""&rs("ca_title"))%></a></h3>            
                    <h4>at <%=server.HTMLEncode(rs("ca_location"))%></h4>

[b]                    <h4>at <%=server.HTMLEncode(rs("ca_address1"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_address2"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_town"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_county"))%></h4>
                    <h4>at <%=server.HTMLEncode(rs("ca_postcode"))%></h4>[/b]


                    <p>
                        <%=server.HTMLEncode(""&rs("ca_summary"))%>
                    </p>
                </td>
                <td width="60" valign="top">
                    <div class="date">
                        <div class="month"><%=server.HTMLEncode(""&monthname(month(rs("ca_startdate")),true))%></div>
                        <div class="day"><%=server.HTMLEncode(""&day(rs("ca_startdate")))%></div>
                    </div>
                    <h4><a href="<%=url%>" class="button small silver"><span>View</span></a></h4>
                </td>
              </tr>
            </table>
        </div>
    <% rs.movenext : wend 
	else %>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>No events matched your query.</p>
        <p>&nbsp;</p>
	<% end if %>
<!--#include virtual="/Assets/Templates/Public/Franchise/TemplateEnd.asp"-->
</body>
</html>
<!--#include virtual="/System/Shutdown.asp"-->

Open in new window


Any help much appreciated.
0
Comment
Question by:UName10
  • 3
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
There is a quick and dirty trick for that:
<h4>at <%=server.HTMLEncode(rs("ca_address1") & "")%></h4>

Open in new window

(and for the other fields as well). This ensures that if a null value occurs in the data then it is silently converted to an empty string. A nicer way would be to use or make a function that checks for the null value and displays a message (if there are not supposed to be null values in the data).
0
 

Author Comment

by:UName10
Comment Utility
Great, thanks for the reply.

I just tried it, but it's still the same unfortunately, can't understand why. It's fine to have null values and the table reflects that. It's a mystery..

It's pointing to the "Type mismatch: 'HTMLEncode'", but not sure why?

Thanks again.
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
Well, normally that would be the excact reason. HTMLEncode expects a string, but gets a null object and rejects it. The same trick I see is already used in the lines before:
<h3><% if len(""&rs("cac_image")) > 0 then %>

Open in new window

This is essentially the same, just the other way around, you could try that but shouldn't make a difference. Have you applied it to all lines? maybe also the one before (ca_location), sometimes the line numbering can be off.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:UName10
Comment Utility
Ahh no I'm sorry - it didn't save as I logged out! Just saw and readded it, now it's worked which is great.

How do I hide them if the fields aren't populated?

Many thanks again.
0
 
LVL 7

Expert Comment

by:Element1910
Comment Utility
- removed solution -

didn't see they already posted something :)
0
 

Author Comment

by:UName10
Comment Utility
Again sorry - it works. Nice solution, thank you.
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
Great!

To hide the empty parts you could do something like earlier in the code:
<% if len(""&rs("ca_address1")) > 0 then %>
<h4>at <%=server.HTMLEncode(rs("ca_address1"))%></h4>
<% end if %>

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now