<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Web Developer - Author(s): kaht</title>
		<link>http://blogs.lessthandot.com/index.php/WebDev/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>Why I sometimes get miscellaneous exclamation marks (!) in SQL generated emails</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/why-i-sometimes-get-miscellaneous-exclam</link>
			<pubDate>Thu, 26 Aug 2010 17:28:06 +0000</pubDate>			<dc:creator>kaht</dc:creator>
			<category domain="main">Server Programming</category>			<guid isPermaLink="false">949@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Using SQL server to generate automatic emails, I&#039;ve noticed from time to time that the emails will miscellaneously contain exclamations throughout the mail.&lt;/p&gt;

&lt;p&gt;Here&#039;s an example to replicate the situation.  We&#039;ll generate a table with multiple rows of the alphabet and email the contents:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb36445&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @t &lt;span style=&quot;color: #0000FF;&quot;&gt;table&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;letters &lt;span style=&quot;color: #0000FF;&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @counter &lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @string &lt;span style=&quot;color: #0000FF;&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;8000&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;set&lt;/span&gt; @counter = &lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;set&lt;/span&gt; @string = &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;insert&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;into&lt;/span&gt; @t&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;abcdefghijklmnopqrstuvwxyz&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;@counter &amp;lt; &lt;span style=&quot;color: #000;&quot;&gt;128&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;insert&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;into&lt;/span&gt; @t&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; letters &lt;span style=&quot;color: #0000FF;&quot;&gt;from&lt;/span&gt; @t&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0000FF;&quot;&gt;set&lt;/span&gt; @counter = &lt;span style=&quot;color: #FF00FF;&quot;&gt;@@rowcount&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; @string = @string + letters + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&amp;lt;br&amp;gt;&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;from&lt;/span&gt; @t&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; @string&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @mailObj &lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;declare&lt;/span&gt; @hr &lt;span style=&quot;color: #0000FF;&quot;&gt;int&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OACreate&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;CDO.Message&#039;&lt;/span&gt;, @mailObj &lt;span style=&quot;color: #0000FF;&quot;&gt;out&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OASetProperty&lt;/span&gt; @mailObj, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;From&#039;&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;sender@server.com&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OASetProperty&lt;/span&gt; @mailObj, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;HTMLBody&#039;&lt;/span&gt;, @string&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OASetProperty&lt;/span&gt; @mailObj, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Subject&#039;&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;test&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OASetProperty&lt;/span&gt; @mailObj, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;To&#039;&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;recipient@server.com&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OAMethod&lt;/span&gt; @mailObj, &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;Send&#039;&lt;/span&gt;, NULL&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;exec&lt;/span&gt; @hr = &lt;span style=&quot;color: #AF0000;&quot;&gt;sp_OADestroy&lt;/span&gt; @mailObj&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb57539&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should kick out the alphabet repeated 256 times, with a &amp;lt;br&amp;gt; tag after each alphabet.  By examining the result in query analyzer, it should look just fine.  However, when you go check the email that got sent, you&#039;ll find parts of the text that look like this:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;codespan&quot;&gt;abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
abcdefghijklmnopqrstuvwxyzabcdef! ghijklmnopqrstuvwxyz&lt;br /&gt;
abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
abcd! efghijklm! nopqrstuvwxyz&lt;br /&gt;
abcdefghijklmnopqrstuvwxyz&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, the solution is fairly simple.  Microsoft Outlook seems to insert these exclamation marks randomly throughout the email when the mail contains no line feeds.&lt;/p&gt;

&lt;p&gt;So, stick a line feed after each alphabet and the exclamation marks will disappear from the email:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb47801&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; @string = @string + letters + &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;&amp;lt;br&amp;gt;&#039;&lt;/span&gt; + &lt;span style=&quot;color: #0000FF;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;from&lt;/span&gt; @t&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb2072&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Piece of cake  &lt;img src=&quot;http://blogs.lessthandot.com/rsc/smilies/icon_cool.gif&quot; title=&quot;B)&quot; alt=&quot;B)&quot; class=&quot;middle&quot; width=&quot;15&quot; height=&quot;15&quot; /&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/why-i-sometimes-get-miscellaneous-exclam&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Using SQL server to generate automatic emails, I've noticed from time to time that the emails will miscellaneously contain exclamations throughout the mail.</p>

<p>Here's an example to replicate the situation.  We'll generate a table with multiple rows of the alphabet and email the contents:</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb47049'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb47049','cb48349'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb47049" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">declare</span> @t <span style="color: #0000FF;">table</span> <span style="color: #808080;">&#40;</span>letters <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">declare</span> @counter <span style="color: #0000FF;">int</span></li><li style="" class="li1"><span style="color: #0000FF;">declare</span> @string <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8000</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">set</span> @counter = <span style="color: #000;">0</span></li><li style="" class="li1"><span style="color: #0000FF;">set</span> @string = <span style="color: #FF0000;">''</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">insert</span> <span style="color: #0000FF;">into</span> @t</li><li style="" class="li2"><span style="color: #0000FF;">select</span> <span style="color: #FF0000;">'abcdefghijklmnopqrstuvwxyz'</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">while</span> <span style="color: #808080;">&#40;</span>@counter &lt; <span style="color: #000;">128</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">begin</span></li><li style="" class="li1">&nbsp; &nbsp;<span style="color: #0000FF;">insert</span> <span style="color: #0000FF;">into</span> @t</li><li style="" class="li2">&nbsp; &nbsp;<span style="color: #0000FF;">select</span> letters <span style="color: #0000FF;">from</span> @t</li><li style="" class="li1">&nbsp; &nbsp;<span style="color: #0000FF;">set</span> @counter = <span style="color: #FF00FF;">@@rowcount</span></li><li style="" class="li2"><span style="color: #0000FF;">end</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">select</span> @string = @string + letters + <span style="color: #FF0000;">'&lt;br&gt;'</span></li><li style="" class="li1"><span style="color: #0000FF;">from</span> @t</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">select</span> @string</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000FF;">declare</span> @mailObj <span style="color: #0000FF;">int</span></li><li style="" class="li2"><span style="color: #0000FF;">declare</span> @hr <span style="color: #0000FF;">int</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OACreate</span> <span style="color: #FF0000;">'CDO.Message'</span>, @mailObj <span style="color: #0000FF;">out</span></li><li style="" class="li1"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OASetProperty</span> @mailObj, <span style="color: #FF0000;">'From'</span>, <span style="color: #FF0000;">'sender@server.com'</span></li><li style="" class="li2"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OASetProperty</span> @mailObj, <span style="color: #FF0000;">'HTMLBody'</span>, @string</li><li style="" class="li1"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OASetProperty</span> @mailObj, <span style="color: #FF0000;">'Subject'</span>, <span style="color: #FF0000;">'test'</span></li><li style="" class="li2"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OASetProperty</span> @mailObj, <span style="color: #FF0000;">'To'</span>, <span style="color: #FF0000;">'recipient@server.com'</span></li><li style="" class="li1"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OAMethod</span> @mailObj, <span style="color: #FF0000;">'Send'</span>, NULL</li><li style="" class="li2"><span style="color: #0000FF;">exec</span> @hr = <span style="color: #AF0000;">sp_OADestroy</span> @mailObj</li></ol></div><div id="cb48349" style="display: none; color: red;"></div></div></div>

<p>This should kick out the alphabet repeated 256 times, with a &lt;br&gt; tag after each alphabet.  By examining the result in query analyzer, it should look just fine.  However, when you go check the email that got sent, you'll find parts of the text that look like this:</p>

<p><code class="codespan">abcdefghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyzabcdef! ghijklmnopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz<br />
.<br />
.<br />
.<br />
abcdefghijklmnopqrstuvwxyz<br />
abcd! efghijklm! nopqrstuvwxyz<br />
abcdefghijklmnopqrstuvwxyz</code></p>

<p>Fortunately, the solution is fairly simple.  Microsoft Outlook seems to insert these exclamation marks randomly throughout the email when the mail contains no line feeds.</p>

<p>So, stick a line feed after each alphabet and the exclamation marks will disappear from the email:</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb35345'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb35345','cb68685'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb35345" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">select</span> @string = @string + letters + <span style="color: #FF0000;">'&lt;br&gt;'</span> + <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span></li><li style="" class="li2"><span style="color: #0000FF;">from</span> @t</li></ol></div><div id="cb68685" style="display: none; color: red;"></div></div></div>

<p>Piece of cake  <img src="http://blogs.lessthandot.com/rsc/smilies/icon_cool.gif" title="B)" alt="B)" class="middle" width="15" height="15" /></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/why-i-sometimes-get-miscellaneous-exclam">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/why-i-sometimes-get-miscellaneous-exclam#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=949</wfw:commentRss>
		</item>
				<item>
			<title>Using ASP to retrieve a recordset and return value from a stored procedure at the same time</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ClassicASP/using-asp-to-retrieve-a-recordset-and-re</link>
			<pubDate>Mon, 10 Aug 2009 18:43:33 +0000</pubDate>			<dc:creator>kaht</dc:creator>
			<category domain="main">Classic ASP</category>			<guid isPermaLink="false">555@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;&lt;em&gt;(This post will use ASP, coded with server side JScript)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When accessing an SQL stored procedure in ASP via ADO, it is typically considered best practice to use the command object:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;asp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;asp&quot; id=&quot;cb98332&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;);&lt;br /&gt;oConn.Open(&amp;quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&amp;quot;);&lt;br /&gt;var oCmd = Server.CreateObject(&amp;quot;ADODB.Command&amp;quot;);&lt;br /&gt;oCmd.ActiveConnection = oConn;&lt;br /&gt;oCmd.CommandType = adCmdStoredProc;&lt;br /&gt;oCmd.CommandText = &amp;quot;StoredProcedureName&amp;quot;;&lt;br /&gt;oCmd.Execute();&lt;br /&gt;oCmd.Close();&lt;br /&gt;oConn.Close();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb12887&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the stored procedure returns a recordset, then the Execute() method of the command object will return a recordset object.&lt;/p&gt;

&lt;p&gt;Consder the following stored procedure:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb6704&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;procedure&lt;/span&gt; TestProcedure &lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;union&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;union&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb7868&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using a command object set up to call this procedure, we can access the returned recordset like so:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;asp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;asp&quot; id=&quot;cb3859&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;);&lt;br /&gt;oConn.Open(&amp;quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&amp;quot;);&lt;br /&gt;var oCmd = Server.CreateObject(&amp;quot;ADODB.Command&amp;quot;);&lt;br /&gt;oCmd.ActiveConnection = oConn;&lt;br /&gt;oCmd.CommandType = adCmdStoredProc;&lt;br /&gt;oCmd.CommandText = &amp;quot;TestProcedure&amp;quot;;&lt;br /&gt;var oRS = oCmd.Execute(); &amp;nbsp;//oRS will contain the recordset returned from the stored procedure&lt;br /&gt;while (!oRS.EOF) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;Response.Write(oRS.Fields(&amp;quot;testValue&amp;quot;).value + &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp;oRS.MoveNext();&lt;br /&gt;}&lt;br /&gt;oRS.Close();&lt;br /&gt;oCmd.Close();&lt;br /&gt;oConn.Close();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb86844&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If a stored procedure returns a return value, then a return value parameter is required on the ADO command object.&lt;/p&gt;

&lt;p&gt;Consider the following procedure:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb51826&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;procedure&lt;/span&gt; TestProcedure2 &lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb62869&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To retrieve the return value in the stored procedure, you have to set up a parameter on the command object to store the return value:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;asp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;asp&quot; id=&quot;cb24987&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;);&lt;br /&gt;oConn.Open(&amp;quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&amp;quot;);&lt;br /&gt;var oCmd = Server.CreateObject(&amp;quot;ADODB.Command&amp;quot;);&lt;br /&gt;oCmd.ActiveConnection = oConn;&lt;br /&gt;oCmd.CommandType = adCmdStoredProc;&lt;br /&gt;oCmd.CommandText = &amp;quot;TestProcedure2&amp;quot;;&lt;br /&gt;oCmd.Parameters.Append(oCmd.CreateParameter(&amp;quot;@returnValue&amp;quot;, adInteger, adParamReturnValue));&lt;br /&gt;oCmd.Execute();&lt;br /&gt;Response.Write(&amp;quot;return value: &amp;quot; + oCmd.Parameters(&amp;quot;@returnValue&amp;quot;).value);&lt;br /&gt;oCmd.Close();&lt;br /&gt;oConn.Close();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb33274&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, things get a little tricky if you have a recordset and a return value in the same procedure:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb69920&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;procedure&lt;/span&gt; TestProcedure3 &lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;union&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;union&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;testValue&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb61434&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The recordset object will be populated correctly, but the return value parameter returns &quot;undefined&quot;:&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;asp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;asp&quot; id=&quot;cb23680&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;);&lt;br /&gt;oConn.Open(&amp;quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&amp;quot;);&lt;br /&gt;var oCmd = Server.CreateObject(&amp;quot;ADODB.Command&amp;quot;);&lt;br /&gt;oCmd.ActiveConnection = oConn;&lt;br /&gt;oCmd.CommandType = adCmdStoredProc;&lt;br /&gt;oCmd.CommandText = &amp;quot;TestProcedure2&amp;quot;;&lt;br /&gt;oCmd.Parameters.Append(oCmd.CreateParameter(&amp;quot;@returnValue&amp;quot;, adInteger, adParamReturnValue));&lt;br /&gt;var oRS = oCmd.Execute();&lt;br /&gt;Response.Write(&amp;quot;return value: &amp;quot; + oCmd.Parameters(&amp;quot;@returnValue&amp;quot;).value);&lt;br /&gt;oCmd.Close();&lt;br /&gt;oConn.Close();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb41862&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One thing that may seem even more odd is that if you do not assign the recordset returned by the procedure to a variable (oRS in the example above), then the returnValue parameter contains the correct value.&lt;/p&gt;

&lt;p&gt;The reason for this is that the recordset returned by the stored procedure must be closed before you can access the returnValue parameter.  I find using the GetRows() method to be extremely handy for this as it allows you to pull all the recordset information into an ASP array and close the recordset immediately afterward, giving you access to both the recordset information and the return value at the same time.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;asp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;asp&quot; id=&quot;cb87744&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;);&lt;br /&gt;oConn.Open(&amp;quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&amp;quot;);&lt;br /&gt;var oCmd = Server.CreateObject(&amp;quot;ADODB.Command&amp;quot;);&lt;br /&gt;oCmd.ActiveConnection = oConn;&lt;br /&gt;oCmd.CommandType = adCmdStoredProc;&lt;br /&gt;oCmd.CommandText = &amp;quot;TestProcedure2&amp;quot;;&lt;br /&gt;oCmd.Parameters.Append(oCmd.CreateParameter(&amp;quot;@returnValue&amp;quot;, adInteger, adParamReturnValue));&lt;br /&gt;var oRS = oCmd.Execute();&lt;br /&gt;if (oRS.RecordCount) {&lt;br /&gt;&amp;nbsp; &amp;nbsp;var recordSetData = oRS.GetRows();&lt;br /&gt;}&lt;br /&gt;oRS.Close()&lt;br /&gt;Response.Write(&amp;quot;return value: &amp;quot; + oCmd.Parameters(&amp;quot;@returnValue&amp;quot;).value);&lt;br /&gt;oCmd.Close();&lt;br /&gt;oConn.Close();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb72643&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ClassicASP/using-asp-to-retrieve-a-recordset-and-re&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p><em>(This post will use ASP, coded with server side JScript)</em></p>

<p>When accessing an SQL stored procedure in ASP via ADO, it is typically considered best practice to use the command object:</p>

<div class="codebox"><div class="codeheader"><span>asp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb87481'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb87481','cb54358'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="asp" id="cb87481" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var oConn = Server.CreateObject(&quot;ADODB.Connection&quot;);</li><li style="" class="li2">oConn.Open(&quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&quot;);</li><li style="" class="li1">var oCmd = Server.CreateObject(&quot;ADODB.Command&quot;);</li><li style="" class="li2">oCmd.ActiveConnection = oConn;</li><li style="" class="li1">oCmd.CommandType = adCmdStoredProc;</li><li style="" class="li2">oCmd.CommandText = &quot;StoredProcedureName&quot;;</li><li style="" class="li1">oCmd.Execute();</li><li style="" class="li2">oCmd.Close();</li><li style="" class="li1">oConn.Close();</li></ol></div><div id="cb54358" style="display: none; color: red;"></div></div></div>

<p>If the stored procedure returns a recordset, then the Execute() method of the command object will return a recordset object.</p>

<p>Consder the following stored procedure:</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb50556'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb50556','cb21822'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb50556" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">create</span> <span style="color: #0000FF;">procedure</span> TestProcedure <span style="color: #0000FF;">as</span></li><li style="" class="li2"><span style="color: #0000FF;">select</span> <span style="color: #000;">1</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">union</span></li><li style="" class="li1"><span style="color: #0000FF;">select</span> <span style="color: #000;">2</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">union</span></li><li style="" class="li2"><span style="color: #0000FF;">select</span> <span style="color: #000;">3</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span></li></ol></div><div id="cb21822" style="display: none; color: red;"></div></div></div>

<p>Using a command object set up to call this procedure, we can access the returned recordset like so:</p>
<div class="codebox"><div class="codeheader"><span>asp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb52351'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb52351','cb19999'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="asp" id="cb52351" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var oConn = Server.CreateObject(&quot;ADODB.Connection&quot;);</li><li style="" class="li2">oConn.Open(&quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&quot;);</li><li style="" class="li1">var oCmd = Server.CreateObject(&quot;ADODB.Command&quot;);</li><li style="" class="li2">oCmd.ActiveConnection = oConn;</li><li style="" class="li1">oCmd.CommandType = adCmdStoredProc;</li><li style="" class="li2">oCmd.CommandText = &quot;TestProcedure&quot;;</li><li style="" class="li1">var oRS = oCmd.Execute(); &nbsp;//oRS will contain the recordset returned from the stored procedure</li><li style="" class="li2">while (!oRS.EOF) {</li><li style="" class="li1">&nbsp; &nbsp;Response.Write(oRS.Fields(&quot;testValue&quot;).value + &quot;&lt;br /&gt;&quot;);</li><li style="" class="li2">&nbsp; &nbsp;oRS.MoveNext();</li><li style="" class="li1">}</li><li style="" class="li2">oRS.Close();</li><li style="" class="li1">oCmd.Close();</li><li style="" class="li2">oConn.Close();</li></ol></div><div id="cb19999" style="display: none; color: red;"></div></div></div>

<p>If a stored procedure returns a return value, then a return value parameter is required on the ADO command object.</p>

<p>Consider the following procedure:</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb48837'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb48837','cb34814'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb48837" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">create</span> <span style="color: #0000FF;">procedure</span> TestProcedure2 <span style="color: #0000FF;">as</span></li><li style="" class="li2"><span style="color: #0000FF;">return</span> <span style="color: #000;">1</span></li></ol></div><div id="cb34814" style="display: none; color: red;"></div></div></div>

<p>To retrieve the return value in the stored procedure, you have to set up a parameter on the command object to store the return value:</p>
<div class="codebox"><div class="codeheader"><span>asp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb70413'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb70413','cb42543'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="asp" id="cb70413" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var oConn = Server.CreateObject(&quot;ADODB.Connection&quot;);</li><li style="" class="li2">oConn.Open(&quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&quot;);</li><li style="" class="li1">var oCmd = Server.CreateObject(&quot;ADODB.Command&quot;);</li><li style="" class="li2">oCmd.ActiveConnection = oConn;</li><li style="" class="li1">oCmd.CommandType = adCmdStoredProc;</li><li style="" class="li2">oCmd.CommandText = &quot;TestProcedure2&quot;;</li><li style="" class="li1">oCmd.Parameters.Append(oCmd.CreateParameter(&quot;@returnValue&quot;, adInteger, adParamReturnValue));</li><li style="" class="li2">oCmd.Execute();</li><li style="" class="li1">Response.Write(&quot;return value: &quot; + oCmd.Parameters(&quot;@returnValue&quot;).value);</li><li style="" class="li2">oCmd.Close();</li><li style="" class="li1">oConn.Close();</li></ol></div><div id="cb42543" style="display: none; color: red;"></div></div></div>

<p>Now, things get a little tricky if you have a recordset and a return value in the same procedure:</p>
<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb53646'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb53646','cb44026'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb53646" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">create</span> <span style="color: #0000FF;">procedure</span> TestProcedure3 <span style="color: #0000FF;">as</span></li><li style="" class="li2"><span style="color: #0000FF;">select</span> <span style="color: #000;">1</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">union</span></li><li style="" class="li1"><span style="color: #0000FF;">select</span> <span style="color: #000;">2</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">union</span></li><li style="" class="li2"><span style="color: #0000FF;">select</span> <span style="color: #000;">3</span> <span style="color: #808080;">&#91;</span>testValue<span style="color: #808080;">&#93;</span> </li><li style="" class="li1"><span style="color: #0000FF;">return</span> <span style="color: #000;">1</span></li></ol></div><div id="cb44026" style="display: none; color: red;"></div></div></div>
<p>The recordset object will be populated correctly, but the return value parameter returns "undefined":</p>
<div class="codebox"><div class="codeheader"><span>asp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb89127'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb89127','cb87503'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="asp" id="cb89127" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var oConn = Server.CreateObject(&quot;ADODB.Connection&quot;);</li><li style="" class="li2">oConn.Open(&quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&quot;);</li><li style="" class="li1">var oCmd = Server.CreateObject(&quot;ADODB.Command&quot;);</li><li style="" class="li2">oCmd.ActiveConnection = oConn;</li><li style="" class="li1">oCmd.CommandType = adCmdStoredProc;</li><li style="" class="li2">oCmd.CommandText = &quot;TestProcedure2&quot;;</li><li style="" class="li1">oCmd.Parameters.Append(oCmd.CreateParameter(&quot;@returnValue&quot;, adInteger, adParamReturnValue));</li><li style="" class="li2">var oRS = oCmd.Execute();</li><li style="" class="li1">Response.Write(&quot;return value: &quot; + oCmd.Parameters(&quot;@returnValue&quot;).value);</li><li style="" class="li2">oCmd.Close();</li><li style="" class="li1">oConn.Close();</li></ol></div><div id="cb87503" style="display: none; color: red;"></div></div></div>

<p>One thing that may seem even more odd is that if you do not assign the recordset returned by the procedure to a variable (oRS in the example above), then the returnValue parameter contains the correct value.</p>

<p>The reason for this is that the recordset returned by the stored procedure must be closed before you can access the returnValue parameter.  I find using the GetRows() method to be extremely handy for this as it allows you to pull all the recordset information into an ASP array and close the recordset immediately afterward, giving you access to both the recordset information and the return value at the same time.</p>

<div class="codebox"><div class="codeheader"><span>asp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb95137'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb95137','cb79815'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="asp" id="cb95137" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var oConn = Server.CreateObject(&quot;ADODB.Connection&quot;);</li><li style="" class="li2">oConn.Open(&quot;Provider=SQLOLEDB; Data Source=ServerName; User Id=ID; Password=PASSWORD&quot;);</li><li style="" class="li1">var oCmd = Server.CreateObject(&quot;ADODB.Command&quot;);</li><li style="" class="li2">oCmd.ActiveConnection = oConn;</li><li style="" class="li1">oCmd.CommandType = adCmdStoredProc;</li><li style="" class="li2">oCmd.CommandText = &quot;TestProcedure2&quot;;</li><li style="" class="li1">oCmd.Parameters.Append(oCmd.CreateParameter(&quot;@returnValue&quot;, adInteger, adParamReturnValue));</li><li style="" class="li2">var oRS = oCmd.Execute();</li><li style="" class="li1">if (oRS.RecordCount) {</li><li style="" class="li2">&nbsp; &nbsp;var recordSetData = oRS.GetRows();</li><li style="" class="li1">}</li><li style="" class="li2">oRS.Close()</li><li style="" class="li1">Response.Write(&quot;return value: &quot; + oCmd.Parameters(&quot;@returnValue&quot;).value);</li><li style="" class="li2">oCmd.Close();</li><li style="" class="li1">oConn.Close();</li></ol></div><div id="cb79815" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ClassicASP/using-asp-to-retrieve-a-recordset-and-re">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ClassicASP/using-asp-to-retrieve-a-recordset-and-re#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=555</wfw:commentRss>
		</item>
				<item>
			<title>Export HTML table to Excel with grid lines</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ASPNET/export-table-to-excel-with-grid-lines</link>
			<pubDate>Thu, 25 Jun 2009 17:47:45 +0000</pubDate>			<dc:creator>kaht</dc:creator>
			<category domain="main">ASP.NET</category>
<category domain="alt">Classic ASP</category>			<guid isPermaLink="false">499@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;&lt;a href=&quot;http://forum.lessthandot.com/viewtopic.php?f=27&amp;amp;t=6448&quot;&gt;http://forum.lessthandot.com/viewtopic.php?f=27&amp;amp;t=6448&lt;/a&gt;&lt;/p&gt;&lt;p&gt;For a long time I have had to make web reports for our company that could be exported to excel. This is a fairly easy process. All you have to do is put your report in an HTML table and add the following 2 lines of code:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb18351&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;ContentType&lt;/span&gt; = &lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;application/ms-excel&amp;quot;&lt;/span&gt;;&lt;br /&gt;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;AddHeader&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;content-disposition&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;attachment; filename=test.xls&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb49002&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, when the excel file is generated it has a nasty side effect of having all the gridlines hidden. They can easily be turned back on in excel by the following: Tools &gt; Options &gt; click gridlines checkbox.&lt;/p&gt;

&lt;p&gt;Until today I put up with the gridlines being hidden. When I tried to search for a solution via google, most people suggested that it just wasn&#039;t possible to generate the excel report with gridlines. Other people offered solutions that required you to run a COM object on the server to start an instance of excel in the background to create the file. However, after searching through a bunch of garbage and piecing together bits and pieces of non-working solutions, I finally got it to work. The trick is to set up your own custom XML settings, and add the &quot;Panes&quot; worksheet option. Here was the working solution:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb70177&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Data&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Configuration&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Collections&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Security&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;UI&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;UI&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;WebControls&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;UI&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;WebControls&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;WebParts&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;using&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;UI&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;HtmlControls&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;namespace&lt;/span&gt; excelGridlineTest&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0600FF;&quot;&gt;public&lt;/span&gt; partial &lt;span style=&quot;color: #FF0000;&quot;&gt;class&lt;/span&gt; _Default : &lt;span style=&quot;color: #000000;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Web&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;UI&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Page&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;void&lt;/span&gt; Page_Load&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;object&lt;/span&gt; sender, EventArgs e&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;ContentType&lt;/span&gt; = &lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;application/ms-excel&amp;quot;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;AddHeader&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;content-disposition&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;attachment; filename=test.xls&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;html xmlns:x=&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;urn:schemas-microsoft-com:office:excel&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;head&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;meta http-equiv=&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;Content-Type&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt; content=&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;text/html;charset=windows-1252&lt;span style=&quot;color: #008080; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;!--[if gte mso 9]&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;xml&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:ExcelWorkbook&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:ExcelWorksheets&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:ExcelWorksheet&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #008080; font-style: italic;&quot;&gt;//this line names the worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:Name&amp;gt;gridlineTest&amp;lt;/x:Name&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:WorksheetOptions&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #008080; font-style: italic;&quot;&gt;//these 2 lines are what works the magic&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;x:Panes&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/x:Panes&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/x:WorksheetOptions&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/x:ExcelWorksheet&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/x:ExcelWorksheets&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/x:ExcelWorkbook&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/xml&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;![endif]--&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/head&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;body&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;table&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;ID&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Name&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Balance&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;1234&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Al Bundy&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;45&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;9876&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Homer Simpson&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;-129&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;5555&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Peter Griffin&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;0&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/table&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/body&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response.&lt;span style=&quot;color: #0000FF;&quot;&gt;Write&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb62533&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Got a web related question?  Discuss it in the forums: &lt;a href=&quot;http://forum.lessthandot.com/&quot;&gt;http://forum.lessthandot.com/&lt;/a&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ASPNET/export-table-to-excel-with-grid-lines&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p><a href="http://forum.lessthandot.com/viewtopic.php?f=27&amp;t=6448">http://forum.lessthandot.com/viewtopic.php?f=27&amp;t=6448</a></p><p>For a long time I have had to make web reports for our company that could be exported to excel. This is a fairly easy process. All you have to do is put your report in an HTML table and add the following 2 lines of code:</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb8740'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb8740','cb56717'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb8740" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Response.<span style="color: #0000FF;">ContentType</span> = <span style="color: #808080;">&quot;application/ms-excel&quot;</span>;</li><li style="" class="li2">Response.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;content-disposition&quot;</span>, <span style="color: #808080;">&quot;attachment; filename=test.xls&quot;</span><span style="color: #000000;">&#41;</span>;</li></ol></div><div id="cb56717" style="display: none; color: red;"></div></div></div>

<p>However, when the excel file is generated it has a nasty side effect of having all the gridlines hidden. They can easily be turned back on in excel by the following: Tools > Options > click gridlines checkbox.</p>

<p>Until today I put up with the gridlines being hidden. When I tried to search for a solution via google, most people suggested that it just wasn't possible to generate the excel report with gridlines. Other people offered solutions that required you to run a COM object on the server to start an instance of excel in the background to create the file. However, after searching through a bunch of garbage and piecing together bits and pieces of non-working solutions, I finally got it to work. The trick is to set up your own custom XML settings, and add the "Panes" worksheet option. Here was the working solution:</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb4416'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb4416','cb56557'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb4416" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>;</li><li style="" class="li2"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Data</span>;</li><li style="" class="li1"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Configuration</span>;</li><li style="" class="li2"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Collections</span>;</li><li style="" class="li1"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>;</li><li style="" class="li2"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Security</span>;</li><li style="" class="li1"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>;</li><li style="" class="li2"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">WebControls</span>;</li><li style="" class="li1"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">WebControls</span>.<span style="color: #0000FF;">WebParts</span>;</li><li style="" class="li2"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">HtmlControls</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">namespace</span> excelGridlineTest</li><li style="" class="li1"><span style="color: #000000;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp;<span style="color: #0600FF;">public</span> partial <span style="color: #FF0000;">class</span> _Default : <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span>.<span style="color: #0000FF;">Page</span></li><li style="" class="li1">&nbsp; &nbsp;<span style="color: #000000;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">ContentType</span> = <span style="color: #808080;">&quot;application/ms-excel&quot;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;content-disposition&quot;</span>, <span style="color: #808080;">&quot;attachment; filename=test.xls&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;html xmlns:x=<span style="color: #008080; font-weight: bold;">\&quot;</span>urn:schemas-microsoft-com:office:excel<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;head&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;meta http-equiv=<span style="color: #008080; font-weight: bold;">\&quot;</span>Content-Type<span style="color: #008080; font-weight: bold;">\&quot;</span> content=<span style="color: #008080; font-weight: bold;">\&quot;</span>text/html;charset=windows-1252<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;!--[if gte mso 9]&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;xml&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:ExcelWorkbook&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:ExcelWorksheets&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:ExcelWorksheet&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//this line names the worksheet</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:Name&gt;gridlineTest&lt;/x:Name&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:WorksheetOptions&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">//these 2 lines are what works the magic</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;x:Panes&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/x:Panes&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/x:WorksheetOptions&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/x:ExcelWorksheet&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/x:ExcelWorksheets&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/x:ExcelWorkbook&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/xml&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;![endif]--&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/head&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;body&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;table&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Balance&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;tr&gt;&lt;td&gt;1234&lt;/td&gt;&lt;td&gt;Al Bundy&lt;/td&gt;&lt;td&gt;45&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;tr&gt;&lt;td&gt;9876&lt;/td&gt;&lt;td&gt;Homer Simpson&lt;/td&gt;&lt;td&gt;-129&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;tr&gt;&lt;td&gt;5555&lt;/td&gt;&lt;td&gt;Peter Griffin&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/table&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/body&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;/html&gt;&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></li><li style="" class="li1">&nbsp; &nbsp;<span style="color: #000000;">&#125;</span></li><li style="" class="li2"><span style="color: #000000;">&#125;</span></li></ol></div><div id="cb56557" style="display: none; color: red;"></div></div></div>

<p>Got a web related question?  Discuss it in the forums: <a href="http://forum.lessthandot.com/">http://forum.lessthandot.com/</a></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ASPNET/export-table-to-excel-with-grid-lines">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/ASPNET/export-table-to-excel-with-grid-lines#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=499</wfw:commentRss>
		</item>
			</channel>
</rss>
