Link to home
Start Free TrialLog in
Avatar of RCairns54
RCairns54

asked on

How do I display html data stored in an ntext or nvarchar(MAX) data type?

I am needing to store large amounts of HTML data in my SQL 2005 database. I have tried using ntext and nvarchar(MAX). I can get the data in the database but I have yet to be able to display it on an ASP web page.

Usually I would create a dataset and display data using this method:
<%=rsPage("PageContent")%>
This method works fine with a nvarchar(255) data type but this type is too small for what I am needing now. Can anyone please help???
Avatar of silemone
silemone
Flag of United States of America image

probably have to call it and then use javascript:  Document.Write(
Avatar of RCairns54
RCairns54

ASKER

Thank you, Im not sure how to do that. Here is a condensed version of the page and how I display data from a dataset:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include virtual="/members_secure.asp" -->
<!--#include virtual="/dbConn.asp" -->
<%
Dim rsMemInfo__ColParam
rsMemInfo__ColParam = "1"
If (Session("Username") <> "") Then
  rsMemInfo__ColParam = Session("Username")
End If
%>
<%
Dim rsMemInfo
Dim rsMemInfo_cmd
Dim rsMemInfo_numRows

Set rsMemInfo_cmd = Server.CreateObject ("ADODB.Command")
rsMemInfo_cmd.ActiveConnection = dbConn_STRING
rsMemInfo_cmd.CommandText = "SELECT * FROM dbo.webpage WHERE User1 = ?"
rsMemInfo_cmd.Prepared = true
rsMemInfo_cmd.Parameters.Append rsMemInfo_cmd.CreateParameter("param1", 200, 1, 255, rsMemInfo__ColParam) ' adVarChar

Set rsMemInfo = rsMemInfo_cmd.Execute
rsMemInfo_numRows = 0
%>
<!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=utf-8" />
<title>Members Page</title>
<link href="/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%=(rsMemInfo.Fields.Item("PageContent").Value)%>
</body>
</html>
<%
rsMemInfo.Close()
Set rsMemInfo = Nothing
%>

The line between the body tags: <%=(rsMemInfo.Fields.Item("PageContent").Value)%> would normaly display as html from smaller data types but for some reason when using ntext or nvarchar(MAX) it won't display.
Change this:

<%=(rsMemInfo.Fields.Item("PageContent").Value)%>

to:

<%
if not rsmeminfo.eof and not rsmeminfo.bof then
response.write rsMemInfo("PageContent")
end if
%>
ASKER CERTIFIED SOLUTION
Avatar of rhodesb
rhodesb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a million! I have been trying to figure this out for quite some time before posting on this website.
Thanks! That is exactly what I needed!