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

Posted on 2013-01-25
Medium Priority
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 
	end if
	if len(""&request.querystring("evtc"))>0 then 
	end if
	if len(""&request.querystring("evtsd"))>0 then 
	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
	end if


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">
<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) {
			defaultDate: '<%=startdate%>',
			onSelect: function(dateText, inst) { $('#evtsd').val(dateText); }
<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"))
			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&"') "
				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">
                <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 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]

                <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>
                    <h4><a href="<%=url%>" class="button small silver"><span>View</span></a></h4>
    <% rs.movenext : wend 
	else %>
        <p>No events matched your query.</p>
	<% end if %>
<!--#include virtual="/Assets/Templates/Public/Franchise/TemplateEnd.asp"-->
<!--#include virtual="/System/Shutdown.asp"-->

Open in new window

Any help much appreciated.
Question by:UName10
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 35

Accepted Solution

Robert Schutt earned 2000 total points
ID: 38820730
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).

Author Comment

ID: 38820748
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.
LVL 35

Expert Comment

by:Robert Schutt
ID: 38820766
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 38820778
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.

Expert Comment

ID: 38820779
- removed solution -

didn't see they already posted something :)

Author Comment

ID: 38820803
Again sorry - it works. Nice solution, thank you.
LVL 35

Expert Comment

by:Robert Schutt
ID: 38820813

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


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

800 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