|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saving HTML into SQL2000Hello 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.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. 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. > 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. 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. > > 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. > >
Other interesting topics
how to obtain further error information?
Can not connect to SQL 2005 Storing Time Only T-SQL Puzzle, well to me at least... multiple parameters for user defined function problem with DBLib access to SQL Server 2005 Find specific text in a string Deleting primary key when no foreign records exist? Old dates big task? |
|||||||||||||||||||||||