Solved

how do you save html text into ms sql table?

Posted on 2014-10-13
7
756 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trigger C# code inside the SQL Server 6 36
Converting Stored Procedure to SQL Statement 5 43
Applying Roles in Common Scenarios 3 19
WordPress Page Content Lost 2 21
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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