How to Store and Retrieve HTML from DB

Posts   
 
    
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 06-Feb-2006 18:28:19   

I have created a shopping cart asp.net application using SQL Server 2000 as the database. In my products table, I have a column called ProductSalesHTMLText that I want the ability to store, retrieve, and assign to a label control on a ProductDetails.aspx page. How do I go about storing HTML formatted text into a SQL 2000 table and retrieve it for dynamic display on the product details page? What data type should I use? What is the best way to get the data copied and pasted into the data column in the table?

Thanks, Wade

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 06-Feb-2006 18:54:57   

Wade wrote:

I have created a shopping cart asp.net application using SQL Server 2000 as the database. In my products table, I have a column called ProductSalesHTMLText that I want the ability to store, retrieve, and assign to a label control on a ProductDetails.aspx page. How do I go about storing HTML formatted text into a SQL 2000 table and retrieve it for dynamic display on the product details page? What data type should I use? What is the best way to get the data copied and pasted into the data column in the table?

Thanks, Wade

Wade,

Are you sure there is an advantage in storing HTML in the database?

Normally you want to separate "data" from "presentation" and hence you would only use the database to store information about the products. ASP.NET is designed to do the rendering for you and hence is the best place to have prsentation logic. You can also cache HTML fragments at the web server if you are trying to improve performance by using a UserControl and setting its cache settings appropriately.

If you must store HTML in the database, then SQL Server 2005 allows you to store native XML in the db which would obviously be an advantage to you... otherwise you should use an text or nText field since it gives you an unlimited size.

JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 06-Feb-2006 19:25:47   

Before you do this, please check out

http://www.thedailywtf.com/forums/28969/ShowPost.aspx

Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 06-Feb-2006 20:14:08   

This is not what I am trying to do. Basically I have a Product Description Column and I want to place some HTML Formatted static text in the DB Table to Stored, retrieve and displayed on the actual Product Detail page. I am not trying to generate dynamic html.

I would think it would be very similar to storing these formatted posts to the forums into a Table then displaying them.

Thanks, Wade

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Feb-2006 20:24:18   

This forum stores pre-rendered HTML blobs in the db (a message is stored both as its original text and as HTML, which is the result of the original text parsed to XML and using an XSL converted to HTML). I use a Text column for that. This to avoid having a column which is too small. So it depends on how big the description will be.

Frans Bouma | Lead developer LLBLGen Pro
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 06-Feb-2006 20:30:57   

Well I am only talking of < 4000 characters.

Do you have some sample code you could post?

Thanks, Wade

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Feb-2006 23:30:36   

Wade wrote:

Well I am only talking of < 4000 characters.

Do you have some sample code you could post?

Thanks, Wade

You then could use a VarChar type, and simply set the property to the HTML text, and save the entity.

Frans Bouma | Lead developer LLBLGen Pro
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 07-Feb-2006 15:59:15   

Do you have any code samples?

The reason I ask is if I try to copy and paste the formatted text into the column I get errors related to length even though I use a column data type of Text or even varchar(4000).

Thanks, Wade

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Feb-2006 17:00:07   

Wade wrote:

Do you have any code samples?

The reason I ask is if I try to copy and paste the formatted text into the column I get errors related to length even though I use a column data type of Text or even varchar(4000).

I already wondered why you would need an example of setting a property wink .

You mean errors from LLBLGen Pro validation code that the length of the string is too long? Or from the db when you save the entity? In the designer, is the length of the field 4000 or smaller?

Frans Bouma | Lead developer LLBLGen Pro
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 08-Feb-2006 20:01:36   

I was trying to just do a copy and paste inside of Query Analyzer and received that message. I am not creating a Products Admin Page with the FreeTextBox control and will save the data via the Product Entity. Hopefully it will work now.

Wade

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Feb-2006 07:24:27   

I tried it before with nText field and it worked fine, but I didn't manually try to copy and paste formatted text (HTML) into Query Analyser