Monday, March 26, 2012

Saving HTML into SQL2000

Hello all,
How do I save the HTML source of a webpage into SQLServer 2000?
Thanks.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.P())
{
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.|||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/defaul...kb;en-us;189415
If you can use XML instead then check out
http://www.perfectxml.com/articles/XML/ImportXMLSQL.asp
John
"Nestor" <test@.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.
>|||thanks guys.. i'll try them out...
"Nestor" <test@.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.
>|||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?
"Jens" <Jens@.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.P())
> {
> 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.
>|||I don=B4t know which coding language you are using, so I can show you
how to make this in C# or any .NET language:
SqlCommand sqlInsertCommand1 =3D new SqlCommand();
SqlConnection sqlConnection1 =3D new SqlConnection("Data
Source=3DSOmeServer;Initital Catalog=3DSomeDB;Integrated Security=3Dtrue");
sqlInsertCommand1.Connection =3D sqlConnection1;
sqlInsertCommand1.CommandType =3D CommandType.Text;
sqlInsertCommand1.CommandText =3D "insert into SomeTable
values(@.SomeHTMLVar)";
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@.SomeHTMLVar",SqlDbType.VarChar,8000));
sqlInsertCommand1.Parameters["@.SomeHTMLVar"].Value =3D
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.

No comments:

Post a Comment