⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ado_getstring.asp@output=print

📁 W3Schools tutorial..web designing
💻 ASP@OUTPUT=PRINT
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>ADO Speed Up Script With getString()</title>
 
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />

<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</head>
<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>ADO Speed Up Script With GetString()</h1>
<a href="ado_demo.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_ref_command.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>
<hr />

<p class="intro">Use the GetString() method to speed up your ASP script (instead 
of using multiple Response.Write's).</p>
<hr />
<h2>Examples</h2>
<p><a target="_blank" href="showasp.asp@filename=demo_display5">Using GetString()</a><br />
How to use GetString() to display data from a recordset in an
HTML table.</p>
<hr />
<h2>Multiple Response.Write's</h2>
<p>The following example demonstrates one way of how to display a  
database query in an HTML table:</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3" id="table1">
  <tr>
    <td>
      <pre>&lt;html&gt;
&lt;body&gt;</pre>
      <pre>&lt;%
set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Provider=&quot;Microsoft.Jet.OLEDB.4.0&quot;
conn.Open &quot;c:/webdata/northwind.mdb&quot;</pre>
      <pre>set rs = Server.CreateObject(&quot;ADODB.recordset&quot;)
rs.Open &quot;SELECT Companyname, Contactname FROM Customers&quot;, conn
%&gt;</pre>
      <pre>&lt;table border=&quot;1&quot; width=&quot;100%&quot;&gt;
&lt;%do until rs.EOF%&gt;
   &lt;tr&gt;
      &lt;td&gt;&lt;%Response.Write(rs.fields(&quot;Companyname&quot;))%&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%Response.Write(rs.fields(&quot;Contactname&quot;))%&gt;&lt;/td&gt;
   &lt;/tr&gt;
&lt;%rs.MoveNext
loop%&gt;
&lt;/table&gt;</pre>
      <pre>&lt;%
rs.close
conn.close
set rs = Nothing<br />set conn = Nothing<br />%&gt;</pre>
      <pre>&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
</table>
<p>For a large query, this can slow down the script processing time, since 
many Response.Write commands must be processed by the server.</p>
<p>The solution is to have the entire string created, from &lt;table&gt; to &lt;/table&gt;, 
and 
then output it - using Response.Write just once.</p>
<hr />
<h2>The GetString() Method</h2>
<p>The GetString() method allows you to display the string with only one Response.Write. 
It also eliminates the do...loop code and the conditional test that checks if 
the recordset is at EOF.</p>
<h3>Syntax</h3>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3" id="table2">
  <tr>
    <td>
      <pre>str = rs.GetString(format,rows,coldel,rowdel,nullexpr)</pre>
    </td>
  </tr>
</table>
<p>To create an HTML table with data from a recordset, we only need to use three of the parameters above 
(all parameters are optional):</p>
<ul>
	<li>coldel - the HTML to use as a column-separator</li>
	<li>rowdel - the HTML to use as a row-separator</li>
	<li>nullexpr - the HTML to use if a column is NULL</li>
</ul>
<p><b>Note:</b> The GetString() method is an ADO 2.0 feature. You can download ADO 2.0 at
<a target="_blank" href="../../www.microsoft.com/data/download.htm">http://www.microsoft.com/data/download.htm</a>.</p>
<p>In the following example we will use the GetString() method to hold the 
recordset as a string: </p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3" id="table3">
  <tr>
    <td>
      <pre>&lt;html&gt;
&lt;body&gt;</pre>
      <pre>&lt;%
set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Provider=&quot;Microsoft.Jet.OLEDB.4.0&quot;
conn.Open &quot;c:/webdata/northwind.mdb&quot;</pre>
      <pre>set rs = Server.CreateObject(&quot;ADODB.recordset&quot;)
rs.Open &quot;SELECT Companyname, Contactname FROM Customers&quot;, conn</pre>
		<pre>str=rs.GetString(,,&quot;&lt;/td&gt;&lt;td&gt;&quot;,&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;,&quot;&amp;nbsp;&quot;)
%&gt;</pre>
      <pre>&lt;table border=&quot;1&quot; width=&quot;100%&quot;&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;%Response.Write(str)%&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;</pre>
		<pre>&lt;%
rs.close
conn.close
set rs = Nothing<br />set conn = Nothing<br />%&gt;</pre>
      <pre>&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
</table>
<p>The str variable above contains a string of all the columns and rows 
returned by the SQL SELECT statement. Between each 
column the HTML 
&lt;/td&gt;&lt;td&gt; will appear, and between each row, the HTML &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; will 
appear. This will produce the exact HTML we need with only one Response.Write.</p>
<hr />
<a href="ado_demo.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_ref_command.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -