Solved

how do you save html text into ms sql table?

Posted on 2014-10-13
7
616 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 45
Numeric sequence in SQL 14 37
SQL Inner Join Vs SubQueries 9 25
remove border from element 5 11
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

757 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

22 Experts available now in Live!

Get 1:1 Help Now