Home All Groups Group Topic Archive Search About

Saving HTML into SQL2000

Author
11 Feb 2006 11:38 AM
Nestor
Hello all,

How do I save the HTML source of a webpage into SQLServer 2000?

Thanks.

Author
11 Feb 2006 11:56 AM
Jens
That a very common question and depends what coding language you are
using, but for .NET solutions the best would be the use of the
WebRequest class:

        public static string getHTMLCode(string URI)
        {
            WebRequest wrq = WebRequest.Create(URI);
            wrq.Timeout = 3000;
            WebResponse wrp = null;
            try
            {
                 wrp = wrq.GetResponse();
                 StreamReader sr = new
StreamReader(wrp.GetResponseStream(), Encoding.ASCII);
                 StringBuilder strBuildContent = new StringBuilder();
                 while (-1 != sr.Peek())
                 {
                     strBuildContent.Append(sr.ReadLine());
                 }

                 return strBuildContent.ToString();
            }
            catch (Exception ex)
            {

                ex = ex;
                return null;
            }

        }

Saving should be something like a normal  saving though a insert
procedure or a insert statement.


HTH, Jens Suessmeyer.
Are all your drivers up to date? click for free checkup

Author
11 Feb 2006 2:49 PM
Nestor
Actaully I've already got the HTML source and the problems in the insertion
due too presence of many characters like ' or ", so SQLServer is not
recognizing the HTML string as a string....

any quick way about this?

Show quoteHide quote
"Jens" <J***@sqlserver2005.de> wrote in message
news:1139658991.300793.254700@z14g2000cwz.googlegroups.com...
> That a very common question and depends what coding language you are
> using, but for .NET solutions the best would be the use of the
> WebRequest class:
>
>         public static string getHTMLCode(string URI)
>         {
>             WebRequest wrq = WebRequest.Create(URI);
>             wrq.Timeout = 3000;
>             WebResponse wrp = null;
>             try
>             {
>                  wrp = wrq.GetResponse();
>                  StreamReader sr = new
> StreamReader(wrp.GetResponseStream(), Encoding.ASCII);
>                  StringBuilder strBuildContent = new StringBuilder();
>                  while (-1 != sr.Peek())
>                  {
>                      strBuildContent.Append(sr.ReadLine());
>                  }
>
>                  return strBuildContent.ToString();
>             }
>             catch (Exception ex)
>             {
>
>                 ex = ex;
>                 return null;
>             }
>
>         }
>
> Saving should be something like a normal  saving though a insert
> procedure or a insert statement.
>
>
> HTH, Jens Suessmeyer.
>
Author
11 Feb 2006 4:27 PM
Jens
I don´t know which coding language you are using, so I can show you
how to make this in C# or any .NET language:

SqlCommand sqlInsertCommand1 = new SqlCommand();
SqlConnection sqlConnection1 = new SqlConnection("Data
Source=SOmeServer;Initital Catalog=SomeDB;Integrated Security=true");
sqlInsertCommand1.Connection = sqlConnection1;

sqlInsertCommand1.CommandType = CommandType.Text;
sqlInsertCommand1.CommandText = "insert into SomeTable
values(@SomeHTMLVar)";

sqlInsertCommand1.Parameters.Add(new
SqlParameter("@SomeHTMLVar",SqlDbType.VarChar,8000));
sqlInsertCommand1.Parameters["@SomeHTMLVar"].Value =
YourParamterwithHTMLCode

        sqlConnection1.Open();
        sqlInsertCommand1.ExecuteNonQuery();

I know that this is not the shortest code, but its just to provide you
with some basic stuff. There are other way to do this like using a
dataadapter and commadnbuilders, but that is one option.

HTH, jens Suessmeyer.
Author
11 Feb 2006 12:46 PM
John Bell
Hi

If you have the page as a file you can load it into a text column using
(say) the textcopy program or
look at using ADOs appendchunk
http://support.microsoft.com/default.aspx?scid=kb;en-us;189415

If you can use XML instead then check out
http://www.perfectxml.com/articles/XML/ImportXMLSQL.asp

John

Show quoteHide quote
"Nestor" <t***@test.com> wrote in message
news:e%23XUe%23vLGHA.648@TK2MSFTNGP14.phx.gbl...
> Hello all,
>
> How do I save the HTML source of a webpage into SQLServer 2000?
>
> Thanks.
>
>
Author
11 Feb 2006 2:16 PM
Nestor
thanks guys.. i'll try them out...

Show quoteHide quote
"Nestor" <t***@test.com> wrote in message
news:e%23XUe%23vLGHA.648@TK2MSFTNGP14.phx.gbl...
> Hello all,
>
> How do I save the HTML source of a webpage into SQLServer 2000?
>
> Thanks.
>
>

Bookmark and Share