?
Solved

how do you save html text into ms sql table?

Posted on 2014-10-13
7
Medium Priority
?
915 Views
Last Modified: 2014-10-15
Have downloaded long html pages from various website pages and want to save them in ms SQl database table

with update code the the update fails as there all sorts of text markers ' and I'm sure lots of other html items which conflict with the syntax required by uypdate code for ms sql

any ideas on how to save the html page in the sql table field ?
0
Comment
Question by:stephenwilde
[X]
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
  • 4
  • 2
7 Comments
 
LVL 40
ID: 40378531
Supposing that you have downloaded the pages into .html files, you can simply read the file into a String with the StreamReader.ReadToEnd method, and save that in a varchar or nvarchar field.
0
 

Author Comment

by:stephenwilde
ID: 40378707
But when the string goes to update sql code it will still have characters such as ' that will not work properly with the sql update.

currently using this code;

WebClient client = new WebClient();
byte[] webpageraw = null;
webpageraw = client.DownloadData(sURL);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string fullHtml = enc.GetString(webpageraw);

Open in new window


then string fullHtml is saved by SQL "update tablename set html = fullHtml "

but fails as fullhtml has characters such as ' that prevent update.
0
 
LVL 11

Expert Comment

by:louisfr
ID: 40381554
Use a parameterized query. It will take care of all the special characters.
0
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

by:stephenwilde
ID: 40381562
It is the html content of a web page that is being saved into a SQL field via an update statement that is causing the problem not the URL.
0
 
LVL 11

Accepted Solution

by:
louisfr earned 2000 total points
ID: 40381585
A parameterized query doesn't care if what you put into the parameter is an URL, HTML, or SQL.
SqlCommand cmd = new SqlCommand("update table set column=@page", connection);
cmd.Parameters.AddWithValue("@page", html);

Open in new window

0
 

Author Comment

by:stephenwilde
ID: 40381591
Thank you for explaining
0
 

Author Closing Comment

by:stephenwilde
ID: 40381592
Thank you
0

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

752 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