<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My Experiments with code</title>
	<atom:link href="http://myexperimentswithcode.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://myexperimentswithcode.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 28 Apr 2009 19:33:47 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='myexperimentswithcode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/78b89524046d31b217917d799af4dcb1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>My Experiments with code</title>
		<link>http://myexperimentswithcode.wordpress.com</link>
	</image>
			<item>
		<title>clickable tr and Show/Hide Panel</title>
		<link>http://myexperimentswithcode.wordpress.com/2009/04/28/clickable-and-showhide-panel/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2009/04/28/clickable-and-showhide-panel/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 19:32:34 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=42</guid>
		<description><![CDATA[Sometimes we may need to code to make an entire row clickable, I mean, the user should click any cell on a tr and a required functionality should be performed as the result of this click. When you cannot use server side coding and rely entirely on client side coding, the below could be one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=42&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes we may need to code to make an entire row clickable, I mean, the user should click any cell on a tr and a required functionality should be performed as the result of this click. When you cannot use server side coding and rely entirely on client side coding, the below could be one of the approaches to this problem.</p>
<p>  <span style="color:#008080;">     </span><span style="color:#008080;"> &lt;asp:Panel ID=&#8221;_pnlContactList&#8221; runat=&#8221;server&#8221; CssClass=&#8221;tableBorder&#8221; Height=&#8221;200px&#8221; ScrollBars=&#8221;Vertical&#8221;&gt;<br />
               &lt;table cellspacing=&#8221;0&#8243; style=&#8221;width: 970px; margin-top:5px; margin-left:10px; margin-bottom:5px; margin-right:5px&#8221; class=&#8221;tableBorder FontNameValue&#8221;&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;FontName tableBorder tdheader&#8221;&gt; Name&lt;/td&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;tableBorder tdheader FontName&#8221;&gt;Title&lt;/td&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;FontName tableBorder tdheader&#8221;&gt;Phone Number&lt;/td&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;tableBorder tdheader FontName&#8221;&gt;Email&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr align=&#8221;left&#8221; onclick=&#8221;Show(1)&#8221;&gt;<br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder&#8221;&gt;Bill&lt;/td&gt;                   <br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder&#8221;&gt;Gates&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder&#8221;&gt;800-000-0000&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder&#8221;&gt;bill.gates@microsoft.com&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr onclick=&#8221;Show(2)&#8221;&gt;<br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder&#8221;&gt;Bill&lt;/td&gt;                      <br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder&#8221;&gt;O&#8217;Reilly&lt;/td&gt; <br />
                    &lt;td class=&#8221;tableBorder&#8221;&gt;800-000-0000&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder&#8221;&gt;bill.reilly@foxnews.com&lt;/td&gt;<br />
                &lt;/tr&gt;&lt;/table&gt;&lt;/asp:Panel&gt;</span></p>
<p>Javascript functions inside &lt;head&gt;</p>
<p><span style="color:#008080;">&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var nameArray = [];<br />
nameArray[1] = &#8220;Bill Gates&#8221;;<br />
nameArray[2] = &#8220;Bill O&#8217;Reilly&#8221;;<br />
nameArray[3] = &#8220;Bill Clinton&#8221;;<br />
nameArray[4] = &#8220;Donald Trump&#8221;;<br />
nameArray[5] = &#8220;Donald Duck&#8221;;<br />
nameArray[6] = &#8220;Donald Rumsfeld&#8221;;<br />
nameArray[7] = &#8220;Home Foreclosure&#8221;;<br />
nameArray[8] = &#8220;Credit Card&#8221;;</span><br />
<span style="color:#008080;">var emailArray = [];<br />
emailArray[1] = &#8220;</span><a href="mailto:bill.gates@microsoft.com"><span style="color:#008080;">bill.gates@microsoft.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[2] = &#8220;</span><a href="mailto:bill.reilly@foxnews.com"><span style="color:#008080;">bill.reilly@foxnews.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[3] = &#8220;</span><a href="mailto:bill.clinton@capitol.com"><span style="color:#008080;">bill.clinton@capitol.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[4] = &#8220;</span><a href="mailto:donald.trump@empire.com"><span style="color:#008080;">donald.trump@empire.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[5] = &#8220;</span><a href="mailto:donald.duck@disney.com"><span style="color:#008080;">donald.duck@disney.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[6] = &#8220;</span><a href="mailto:donald.rumsfeld@state.com"><span style="color:#008080;">donald.rumsfeld@state.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[7] = &#8220;</span><a href="mailto:home.foreclosure@states.com"><span style="color:#008080;">home.foreclosure@states.com</span></a><span style="color:#008080;">&#8220;;<br />
emailArray[8] = &#8220;</span><a href="mailto:credit.card@debt.com"><span style="color:#008080;">credit.card@debt.com</span></a><span style="color:#008080;">&#8220;;</span></p>
<p> </p>
<p><span style="color:#008080;">    function Hide()<br />
    {<br />
        document.getElementById(&#8216;_divPnl&#8217;).style.visibility = &#8216;hidden&#8217;;<br />
    }</span></p>
<p><span style="color:#008080;">    function Show()<br />
    {<br />
        document.getElementById(&#8216;_divPnl&#8217;).style.visibility = &#8216;visible&#8217;;<br />
    }<br />
   <br />
    function Show(elem)<br />
    {       <br />
        for(var i=1; i&lt;=8; i++)<br />
        {<br />
            if(elem == i) <br />
            {         <br />
                document.getElementById(&#8216;name&#8217;).innerHTML = nameArray[i];<br />
                document.getElementById(&#8216;email&#8217;).innerHTML = emailArray[i];<br />
                document.getElementById(&#8216;_divPnl&#8217;).style.visibility = &#8216;visible&#8217;;<br />
            }<br />
        }<br />
   }</span></p>
<p><span style="color:#008080;">&lt;/script&gt;</span></p>
<p>coming back to markup:</p>
<p>in my case, i want to show a panel when a tr is clicked, this panel will contain detailed information relevant to the &lt;tr&gt;. this panel would be initially hidden, and when the &lt;tr&gt; is clicked, will be displayed.</p>
<p>  <span style="color:#008080;">          &lt;div id=&#8221;_divPnl&#8221; style=&#8221;visibility:hidden&#8221;&gt;<br />
        &lt;asp:Panel ID=&#8221;_pnlContactDetails&#8221; runat=&#8221;server&#8221; CssClass=&#8221;tableBorder&#8221; Height=&#8221;170px&#8221;&gt;<br />
               &lt;table cellspacing=&#8221;0&#8243; style=&#8221;width: 970px; margin-top:5px; margin-left:10px&#8221; class=&#8221;tableBorder&#8221;&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;FontName tableBorder tdheader&#8221;&gt;<br />
                        Address&lt;/td&gt;<br />
                        &lt;td class=&#8221;tableBorder tdheader&#8221; style=&#8221;color:Silver&#8221;&gt;none&lt;/td&gt;<br />
                    &lt;td align=&#8221;center&#8221; class=&#8221;FontName tableBorder tdheader&#8221; style=&#8221;color:Silver&#8221;&gt;none<br />
                        &lt;/td&gt;<br />
                        &lt;td class=&#8221;tableBorder tdheader&#8221; style=&#8221;color:Silver&#8221;&gt;none&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr&gt;<br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder FontName&#8221;&gt;Name&lt;/td&gt;<br />
                    &lt;td id=&#8221;name&#8221; align=&#8221;left&#8221; class=&#8221;tableBorder FontNameValue&#8221;&gt;&lt;/td&gt;  </span><span style="color:#008080;"><span style="color:#993366;">//empty &lt;td&gt;, value will be dynamically displayed using &lt;script&gt; functions<br />
</span>                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Title&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;Mr. &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder FontName&#8221;&gt;<br />
                        Address Line 1&lt;/td&gt;<br />
                    &lt;td align=&#8221;left&#8221; class=&#8221;tableBorder FontNameValue&#8221;&gt;I-275 W<br />
                    &lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Telephone Number&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;888-890-9021&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Address Line 2&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;Apt O&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Cell Phone Number&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;888-888-8888&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;City&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;Cincinnati&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Fax Number&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;800-000-0000&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
               <br />
                &lt;tr&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;State&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;OH&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Email Address&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;&lt;a href=&#8221;</span><a href="mailto:someone@somewhere.com"><span style="color:#008080;">someone@somewhere.com</span></a><span style="color:#008080;">&#8221; id=&#8221;email&#8221;&gt;&lt;/a&gt;&lt;/td&gt;<br />
                &lt;/tr&gt;</span></p>
<p><span style="color:#008080;">                &lt;tr&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Zip Code&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;00000&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontName&#8221;&gt;Contact Type&lt;/td&gt;<br />
                    &lt;td class=&#8221;tableBorder FontNameValue&#8221;&gt;Customer&lt;/td&gt;<br />
                &lt;/tr&gt;<br />
            &lt;/table&gt;<br />
        &lt;/asp:Panel&gt;<br />
        &lt;/div&gt;</span></p>
<p> </p>
<p><span style="color:#000000;">References:</span></p>
<p><span style="color:#008080;"><span style="color:#000000;">1. </span><a href="http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=312"><span style="color:#000000;">http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=312</span></a></span></p>
<p><span style="color:#008080;"><span style="color:#000000;">2. </span><a href="http://www.devx.com/tips/Tip/13638"><span style="color:#000000;">http://www.devx.com/tips/Tip/13638</span></a></span></p>
<p><span style="color:#008080;"><span style="color:#000000;">3. </span><a href="http://www.tizag.com/javascriptT/javascript-getelementbyid.php"><span style="color:#000000;">http://www.tizag.com/javascriptT/javascript-getelementbyid.php</span></a></span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=42&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2009/04/28/clickable-and-showhide-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>SELECT from EXEC StoredProc</title>
		<link>http://myexperimentswithcode.wordpress.com/2009/04/20/select-from-exec-storedproc/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2009/04/20/select-from-exec-storedproc/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 17:33:36 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=39</guid>
		<description><![CDATA[If you want to retrieve the results of EXECuting a Stored Proc the most common way is to create a temp table and insert the results of EXEC stored proc into this table. The table designs of the temp table and the result of the EXEC storedproc should be the same.
Example:
CREATE TABLE #TEMP
(CONTACTID INT,
CONTACTTITLE VARCHAR(50),
CONTACTFIRSTNAME [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=39&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you want to retrieve the results of EXECuting a Stored Proc the most common way is to create a temp table and insert the results of EXEC stored proc into this table. The table designs of the temp table and the result of the EXEC storedproc should be the same.</p>
<p>Example:</p>
<p><strong>CREATE TABLE #TEMP<br />
(CONTACTID INT,<br />
CONTACTTITLE VARCHAR(50),<br />
CONTACTFIRSTNAME VARCHAR(50),<br />
CONTACTLASTNAME VARCHAR(50),<br />
FAX VARCHAR(20),<br />
PHONE1 VARCHAR(20),<br />
PHONE2 VARCHAR(20),<br />
EMAIL VARCHAR(50),<br />
CONTACTTYPEID INT,<br />
LOCATIOND INT<br />
)<br />
INSERT INTO #TEMP EXEC wtg_ContactMasterGet 4<br />
SELECT * FROM #TEMP</strong></p>
<p>Here the stored proc wtg_ContactMasterGet  takes a parameter 4 and returns a result set. The types of the result set must match with the table design of the temp table.</p>
<p> </p>
<p>References: <a href="http://www.sqlteam.com/article/return-recordsets-from-dynamic-queries-called-by-exec">http://www.sqlteam.com/article/return-recordsets-from-dynamic-queries-called-by-exec</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=39&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2009/04/20/select-from-exec-storedproc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET WebParts on SharePoint &#8211; For a Beginner</title>
		<link>http://myexperimentswithcode.wordpress.com/2009/04/03/aspnet-webparts-on-sharepoint-for-a-beginner/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2009/04/03/aspnet-webparts-on-sharepoint-for-a-beginner/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 16:51:50 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=36</guid>
		<description><![CDATA[Environment: .NET 3.5, ASP.NET, SharePoint, WSS 3.0, VS 2008, C#
With VS 2008 comes SharePoint templates. To get to this:
Step 1: New Project-&#62; Windows -&#62; SharePoint (LHS) -&#62; Click on WebPart template (RHS)
Step 2: Open the WebPart1 project
Step 3: Uncomment the C# code in WebPart1.cs in CreateChildControls()
Step 4: Save. In Solution Explorer, Right click on Deploy.
Step [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=36&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Environment: .NET 3.5, ASP.NET, SharePoint, WSS 3.0, VS 2008, C#</p>
<p>With VS 2008 comes SharePoint templates. To get to this:</p>
<p><strong>Step 1: New Project</strong>-&gt; <strong>Windows</strong> -&gt; <strong>SharePoint</strong> (LHS) -&gt; Click on <strong>WebPart</strong> template (RHS)</p>
<p>Step 2: Open the WebPart1 project</p>
<p>Step 3: Uncomment the C# code in WebPart1.cs in <strong>CreateChildControls()</strong></p>
<p>Step 4: Save. In Solution Explorer, Right click on Deploy.</p>
<p>Step 5: In <strong>C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config</strong> (aka 12-hive) do the following:</p>
<p style="padding-left:60px;">5.1 <strong>&lt;compilation&gt; </strong>set<strong> debug = true</strong> To enable debugging on WebPart code</p>
<p style="padding-left:60px;">5.2 <strong>&lt;customErrors&gt; </strong>set <strong>Off.</strong> As a dev you want to see the actual error output<strong>.</strong></p>
<p style="padding-left:60px;">5.3 <strong>&lt;CallStack&gt; </strong>set <strong>True.</strong> You want to see the error stack trace to pinpoint the error</p>
<p style="padding-left:60px;">5.4 <strong>&lt;ApplicationPageLevelTrace&gt;</strong> set <strong>True.</strong> You want to view page level tracing</p>
<p>Step 6: <strong>Build, Run </strong></p>
<p>Step 7: <a href="http://localhost"><strong>http://localhost</strong></a> will change to <a href="http://mossdev/default.aspx?PageView=Shared"><strong>http://mossdev/default.aspx?PageView=Shared</strong></a><strong>. Site Actions-&gt;Edit Mode -&gt; </strong>Click<strong> &#8216;Add a Web Part&#8217;. </strong>Select <strong>WebPart1 from the list. </strong>Click <strong>Add.</strong>  </p>
<p>Reference:</p>
<p><a href="http://visualstudiomagazine.com/features/article.aspx?editorialsid=2644">http://visualstudiomagazine.com/features/article.aspx?editorialsid=2644</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=36&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2009/04/03/aspnet-webparts-on-sharepoint-for-a-beginner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>Open a .doc or .xls as .pdf aka Convert .doc or .xls to .pdf</title>
		<link>http://myexperimentswithcode.wordpress.com/2009/04/01/open-a-doc-or-xls-as-pdf-aka-convert-doc-or-xls-to-pdf/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2009/04/01/open-a-doc-or-xls-as-pdf-aka-convert-doc-or-xls-to-pdf/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 13:48:13 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[.doc]]></category>
		<category><![CDATA[.pdf]]></category>
		<category><![CDATA[.xls]]></category>
		<category><![CDATA[convert]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=24</guid>
		<description><![CDATA[One of my recent tasks was to code to open a .doc or .xls as .pdf. The file should open as .pdf and then it&#8217;s upto the user to save the .pdf. I tell you I had to scourge the internet looking for good leads. There are many articles in www.codeproject.com, many threads in asp.net [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=24&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of my recent tasks was to code to open a .doc or .xls as .pdf. The file should open as .pdf and then it&#8217;s upto the user to save the .pdf. I tell you I had to scourge the internet looking for good leads. There are many articles in <a href="http://www.codeproject.com">www.codeproject.com</a>, many threads in asp.net forums, and one project called iTextDotNet in <a href="http://www.sourceforge.net">www.sourceforge.net</a>, a few blogs &#8211; all related to the same topic. But it was in <a href="http://www.msdn.com">www.msdn.com</a> I found what I needed. I immediately tested it and cooooollllllll&#8230;&#8230;gotcha. For developers, here you go&#8230;.</p>
<p>I did this in VS 2008 and Office 2007. I know this works good on .docx, .xlsx(Office 2007), .doc (Microsoft Office Word 97 &#8211; 2003 Document), .xls (Microsoft Office Excel 97-2003 Worksheet) &#8211; I couldn&#8217;t try this code on Office 2003 directly but I saved the files in Office 2003 Compatible format and it works good.</p>
<p>TODO:</p>
<div><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;"><span style="color:#000000;">1. Add namespaces</span></span></span></div>
<p> </p>
<p> </p>
<p><span style="font-size:x-small;color:#0000ff;"></span> </p>
<div><span style="color:#000000;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>using </strong></span></span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>MSExcel = Microsoft.Office.Interop.Excel</strong>;//Add References-&gt; COM</span></span></span></span></div>
<div><span style="color:#000000;"><span style="font-size:x-small;"></span></span> </div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;"><span style="color:#000000;">2. Install Addin : SaveAsPDFAndXPS</span></span></span></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#008000;"></span></span></span> </div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;"><span style="color:#000000;">//code</span></span></span></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="color:#000000;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;">object</span></span><span style="font-size:x-small;"> Unknown = </span><span style="font-size:x-small;"><span style="font-size:x-small;">Type</span></span><span style="font-size:x-small;">.Missing;</span></strong></span></span> </span></span></span></div>
<div><span style="font-size:x-small;"></span> </div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>MSWord.</strong></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">Application</span></span><span style="font-size:x-small;"> newApp = </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">new</span></span><span style="font-size:x-small;"> Microsoft.Office.Interop.Word.</span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">Application();</span></span></strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;color:#000000;">//source document</span></span></span></span></strong></span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;color:#000000;">object </span></span></span></span></strong></span></span><span style="color:black;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;color:black;">src_doc = </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">&#8220;C:\Users\admin\Desktop\DocumentViewer\test.docx&#8221;</span></span></span></span></span></span><span style="font-size:x-small;color:#000000;"><span style="font-size:x-small;"><span style="color:black;">;</span><span style="font-size:x-small;"> </span></span></span></span></strong></span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:#000000;"></span></span></strong></span></span> </div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong></strong></span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong></strong></span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"><strong></strong></span></span></div>
<div><span style="color:black;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;">newApp.Documents.Open(</span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:black;">ref</span></span><span style="font-size:x-small;"> src_doc, </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">ref </span></span></span></span></strong><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;">Unknown,<span style="font-size:x-small;"> </span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref </span></span></span></span></span></span><span style="font-size:x-small;">Unknown,<span style="font-size:x-small;">  </span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref </span></span></span></span></strong><span style="font-size:x-small;"><strong>Unknown);</strong><span style="font-size:x-small;"><span style="font-size:x-small;">  </span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;">//# of params 16, # of Unknowns 14</span></span></span></span></div>
<div><span style="color:black;"><span style="font-size:x-small;"></span></span> </div>
<div><span style="color:black;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><strong></strong></span></span></strong></span></div>
<div><span style="color:black;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;">//save as PDF</span></span></strong></span></span></strong></span></div>
<div><span style="color:black;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><strong></strong></span></span></strong></span><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong>object </strong></span></span></span></span></span></span><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong><span style="font-size:x-small;color:#000000;">format = MSWord.</span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">WdSaveFormat</span></span><span style="font-size:x-small;"><span style="color:#000000;">.wdFormatPDF;</span></span></strong></span></span></span></span></span></span></span></span></div>
<div><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong></strong></span></span></span></span></span></span></span></span> </div>
<div><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong></strong></span></span></span></span></span></span></span></span></div>
<div><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong></strong></span></span></span></span></span></span></span></span></div>
<div><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong></strong></span></span></span></span></span></span></span></span></div>
<div><span style="color:black;"><span style="color:#2b91af;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><strong></strong></span></span></span></span></span></span></span></span><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;">newApp.ActiveDocument.SaveAs(</span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> des_doc, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> format, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref </span></span></span></span></span></strong><span style="font-size:x-small;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;">Unknown,<span style="font-size:x-small;"> </span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref </span></span></span></span></span></span><span style="font-size:x-small;">Unknown,<span style="font-size:x-small;"> </span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown);</span></span></span></strong></span></div>
<div><span style="font-size:x-small;"><strong><span style="font-size:x-small;"></span></strong></span> </div>
<div><span style="font-size:x-small;"><strong></strong></span></div>
<div><span style="font-size:x-small;"><strong></strong></span></div>
<div><strong></strong></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong></strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">object</span></span><span style="font-size:x-small;"> des_doc= </span><span style="font-size:x-small;color:black;"><span style="font-size:x-small;color:black;">&#8220;C:\Users\admin\Desktop\DocumentViewer\test.pdf&#8221;</span></span><span style="font-size:x-small;">;</span></strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong></strong></span></span> </div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;">newApp.Quit(</span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">ref</span></span><span style="font-size:x-small;"> Unknown);</span></span></strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></div>
<div><span style="color:#339966;"><strong>//now to open .xls as .pdf</strong> </span></div>
<p><strong><span style="font-size:x-small;"><span style="font-size:x-small;">MSExcel.</span></span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">Application</span></span><span style="font-size:x-small;"> newExcelAppn = </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">new</span></span><span style="font-size:x-small;"> Microsoft.Office.Interop.Excel.</span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">Application </span></span><span style="font-size:x-small;">();</span></strong></p>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;">MSExcel.</span></span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">Workbook</span></span><span style="font-size:x-small;"> newbook = </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">null</span></span><span style="font-size:x-small;">;<span style="font-size:x-small;"> </span></span></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></strong></div>
<div><strong><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">string</span></span><span style="font-size:x-small;"> src_xls = </span><span style="font-size:x-small;color:#a31515;"><span style="font-size:x-small;color:#a31515;">&#8220;C:\Users\admin\Desktop\DocumentViewer\To_Bret_Conard.xlsx&#8221;</span></span><span style="font-size:x-small;">;<span style="font-size:x-small;"> </span></span></strong></div>
<div><strong></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">object</span></span><span style="font-size:x-small;"> des_xls = </span><span style="font-size:x-small;color:#a31515;"><span style="font-size:x-small;color:#a31515;">&#8220;C:\Users\admin\Desktop\DocumentViewer\To_Bret_Conard.pdf&#8221;</span></span><span style="font-size:x-small;">;</span></strong></div>
<div><strong></strong> </div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong><span style="font-size:x-small;">newbook = newExcelAppn.Workbooks.Open(src_xls, </span><span style="font-size:x-small;">Unknown, Unknown, Unknown, Unknown, </span></strong><span style="font-size:x-small;"><strong>Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown);</strong></span></div>
<div><span style="font-size:x-small;"><strong></strong></span> </div>
<div><span style="font-size:x-small;"><strong></strong></span></div>
<div><span style="font-size:x-small;"><strong></strong></span></div>
<div><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;"><strong></strong></span></span></div>
<div><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;"><strong>//specify the format. PDF</strong></span></span><span style="font-size:x-small;"><strong> </strong></span></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;">MSExcel.</span></span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">XlFixedFormatType</span></span><span style="font-size:x-small;"> paramExportFormat = MSExcel.</span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">XlFixedFormatType</span></span><span style="font-size:x-small;">.xlTypePDF;<span style="font-size:x-small;"> </span></span></strong></div>
<div><strong></strong> </div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;">// Save it in the target format. </span></span></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;">newbook.ExportAsFixedFormat(paramExportFormat, des_xls, MSExcel.</span></span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">XlFixedFormatQuality</span></span><span style="font-size:x-small;">.xlQualityStandard,<span style="font-size:x-small;"> </span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">true</span></span><span style="font-size:x-small;">, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">true</span></span><span style="font-size:x-small;">, Unknown, Unknown, </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">false</span></span><span style="font-size:x-small;">, Unknown);</span></strong></div>
<div><strong></strong> </div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><span style="font-size:x-small;"><strong></strong></span></div>
<div><span style="font-size:x-small;"><strong>newExcelAppn.Quit();</strong></span></div>
<div><strong></strong></div>
<p> <span style="font-size:x-small;"><span style="font-size:x-small;"><strong> <span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;">//view the pdf in browser</span></span></strong></span></span> </p>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">byte</span></span><span style="font-size:x-small;">[] buffer = </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">new</span></span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">byte</span></span><span style="font-size:x-small;">[1024];<span style="font-size:x-small;"> </span></span></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></strong></div>
<div><strong><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">long </span></span><span style="font-size:x-small;">byteCount;</span></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong> </div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;">inStr =</span></span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">File</span></span><span style="font-size:x-small;">.OpenRead(</span><span style="font-size:x-small;color:#a31515;"><span style="font-size:x-small;color:#a31515;">&#8220;C:\Users\admin\Desktop\DocumentViewer\To_Bret_Conard.pdf&#8221;</span></span><span style="font-size:x-small;">);<span style="font-size:x-small;"> </span></span></strong></div>
<div><strong><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></strong></div>
<div><strong><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">while</span></span><span style="font-size:x-small;">((byteCount = inStr.Read(buffer, 0, buffer.Length)) &gt; 0)</span></strong></div>
<div><strong><span style="font-size:x-small;">{</span></strong></div>
<div style="padding-left:30px;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">if</span></span><span style="font-size:x-small;">(Context.Response.IsClientConnected)</span></strong></span></div>
<div style="padding-left:30px;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>{</strong></span></span></div>
<div style="padding-left:60px;"><span style="font-size:x-small;"><strong><span style="font-size:x-small;"><span style="font-size:x-small;">Context.Response.ContentType = </span></span><span style="font-size:x-small;color:#a31515;"><span style="font-size:x-small;color:#a31515;">&#8220;application/pdf&#8221;</span></span><span style="font-size:x-small;">;</span></strong></span></div>
<div style="padding-left:60px;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>Context.Response.OutputStream.Write(buffer, 0, buffer.Length);</strong></span></span></div>
<div style="padding-left:60px;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>Context.Response.Flush();</strong></span></span></div>
<div style="padding-left:30px;"><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>}</strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong>}</strong></span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;"><strong></strong></span></span> </div>
<div><span style="font-size:x-small;">References: </span></div>
<div><span style="font-size:x-small;"><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.exportasfixedformat.aspx">http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.exportasfixedformat.aspx</a></span></div>
<p><span style="font-size:x-small;"><a href="http://msdn.microsoft.com/en-us/library/bb407651.aspx">http://msdn.microsoft.com/en-us/library/bb407651.aspx</a></span></p>
<p><span style="font-size:x-small;"><a href="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f8989c05-d04a-4b4a-be0f-fc0055691de7">http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f8989c05-d04a-4b4a-be0f-fc0055691de7</a></span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=24&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2009/04/01/open-a-doc-or-xls-as-pdf-aka-convert-doc-or-xls-to-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>Refresh page whenever required</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/08/02/refresh-page-whenever-required/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/08/02/refresh-page-whenever-required/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 00:12:51 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=20</guid>
		<description><![CDATA[To refresh/reload a page, there are many javascript ways. Here I am going to discuss about one of them. This feature is not widely available in the internet. I searched and realized!!!. The method goes thus:
ClientScript.RegisterStartupScript(GetType(),&#8221;keyString&#8221;, &#8220;javascriptString&#8221;);
string javascriptString = &#8220;&#60;script language=&#8217;javascript&#8217;&#62;functionToRefresh();&#60;/script&#62; 
// string keyString &#8211; this keyString serves as a key to the &#8216;javascriptString&#8217;. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=20&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>To refresh/reload a page, there are many javascript ways. Here I am going to discuss about one of them. This feature is not widely available in the internet. I searched and realized!!!. The method goes thus:</p>
<p><strong>ClientScript.RegisterStartupScript(GetType(),&#8221;keyString&#8221;, &#8220;javascriptString&#8221;);</strong></p>
<p><strong>string javascriptString = &#8220;&lt;script language=&#8217;javascript&#8217;&gt;functionToRefresh();&lt;/script&gt; </strong></p>
<p>// string keyString &#8211; this keyString serves as a key to the &#8216;javascriptString&#8217;. This means I can use one keystring for the same function anywhere in the code to call the page refresh javascript function.</p>
<p>The &#8216;functionToRefresh()&#8217; should be entered in the .aspx page and the above code should be entered in the .aspx.cs. Thats it. I include these 2 snippets in any page I want to refresh. Whenever after any task is performed, if i want a page refresh I&#8217;ll iclude these 2 code pieces.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=20&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/08/02/refresh-page-whenever-required/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>Money and Date display</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/08/02/money-and-date-display/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/08/02/money-and-date-display/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 23:46:34 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=17</guid>
		<description><![CDATA[Very often we are required to display date and money values on the webpages. In the SQL Server database, the date is stored as SQLDBType.Datetime and the currency values are stored as SBLDBType.Money.
In the C# code, the  SQLDBType.Datetime should be converted to System.DateTime and SBLDBType.Money to System.decimal:
Datetime d = Convert.ToDateTime( SBLDBType.DateTime variable);

decimal m = Convert.ToDecimal( [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=17&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Very often we are required to display date and money values on the webpages. In the SQL Server database, the date is stored as<strong> SQLDBType.Datetime</strong> and the currency values are stored as <strong>SBLDBType.Money</strong>.</p>
<p>In the C# code, the  SQLDBType.Datetime should be converted to <strong>System.DateTime</strong> and SBLDBType.Money to <strong>System.decimal</strong>:</p>
<p><strong>Datetime d = Convert.ToDateTime( SBLDBType.DateTime variable);</strong><strong><br />
</strong></p>
<p><strong>decimal m = Convert.ToDecimal( </strong><strong>SBLDBType.Money variable);</strong></p>
<p>In the Source page, these values can be displayed as:</p>
<p><strong>&lt;%# DataBinder.Eval(Container.DateItem, &#8220;Money&#8221;, &#8220;{0:c}&#8221; %&gt; //here Money is column name</strong></p>
<p><strong>&lt;%# DataBinder.Eval(Container.DateItem, &#8220;date&#8221;, &#8220;{0:d}&#8221; %&gt; </strong><strong>//here date is column name</strong></p>
<p>provided the values are coming from database.</p>
<p>In the code-behind, these values can be defined as:</p>
<p><strong>label1.Text = </strong><strong>String.Format(&#8220;{0:c}&#8221;, SQLmoneyVariable)</strong></p>
<p><strong>label2.Text = String.Format(&#8220;{0:d}&#8221;, SQLdateVariable)</strong></p>
<p>This will cause the labels to display money and date values on the webpage. String.Format is used to return the date and currency values as string in the required format.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=17&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/08/02/money-and-date-display/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>Data-binding expressions</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/07/04/data-binding-expressions/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/07/04/data-binding-expressions/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 23:25:53 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Bind]]></category>
		<category><![CDATA[Databinding expressions]]></category>
		<category><![CDATA[Eval]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=15</guid>
		<description><![CDATA[When working with Databound controls, very often we are required to work with templates, may be they are ItemTemplates, EditItemTemplates, InsertItemTemplates etc.  In these situations usually we&#8217;ll use data-binding expressions.
There are 3 types of commonly used Data-binding expressions.
1. Type I &#8211; &#60;%# Eval(&#8220;column_name&#8221;) %&#62;
The above expression is a 2-way expression, meaning you can read/write values. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=15&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When working with Databound controls, very often we are required to work with templates, may be they are ItemTemplates, EditItemTemplates, InsertItemTemplates etc.  In these situations usually we&#8217;ll use data-binding expressions.</p>
<p>There are 3 types of commonly used Data-binding expressions.</p>
<p>1. Type I &#8211; <strong>&lt;%# Eval(&#8220;column_name&#8221;) %&gt;</strong></p>
<p>The above expression is a 2-way expression, meaning you can read/write values. Commonly used in TextBoxes.</p>
<p><strong>&lt;asp:TextBox text =</strong> <strong>&#8216;&lt;%# Eval(&#8220;LastName&#8221;) %&gt;</strong></p>
<p>2. Type II &#8211; <strong>&lt;%# Bind(column_name) %&gt;</strong></p>
<p>The above expression is a 1-way expression, meaning you can only read values. Commonly used in DropDownLists, Listboxes, labels.</p>
<p><strong>&lt;asp:DropDownList SelectedValue = &lt;%# Bind(&#8220;LastName&#8221;) %&gt;</strong></p>
<p>3. Type III &#8211; <strong>&lt;%# Function() || variable %&gt;</strong></p>
<p>Examples:<strong> &lt;%# SomeMethod() %&gt;</strong></p>
<p><strong> &lt;%# firstName %&gt;</strong></p>
<p><strong> &lt;%# (firstname)+&#8217; &#8216;+(lastname) %&gt;</strong></p>
<p>Reference: http://msdn.microsoft.com/en-us/library/ms178366(VS.80).aspx, http://bhaidar.net/cs/archive/2006/08/04/473.aspx</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=15&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/07/04/data-binding-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>JOIN in DataSets &#8211; Good idea or bad idea?</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/07/04/join-in-datasets-good-idea-or-bad-idea/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/07/04/join-in-datasets-good-idea-or-bad-idea/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 22:38:54 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[dataset]]></category>
		<category><![CDATA[JOIN]]></category>
		<category><![CDATA[subquery]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=14</guid>
		<description><![CDATA[Very often we programmers are needed to use JOIN statements in our code.  We use JOINs to configure DataSource controls, populate Datasets, etc.
SELECT statements would be used to join  2,3 or more tables. So far so good. But problem arises when using UPDATE, DELETE, INSERT statements. It is not possible to update 2 or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=14&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Very often we programmers are needed to use JOIN statements in our code.  We use JOINs to configure DataSource controls, populate Datasets, etc.</p>
<p>SELECT statements would be used to join  2,3 or more tables. So far so good. But problem arises when using UPDATE, DELETE, INSERT statements. It is not possible to update 2 or more tables in one statement. Also UPDATE, INSERT, DELETE statements would not be automatically generated when configuring the data source. The programmer has to code these statements.</p>
<p>To avoid these difficulties and to make our lives easy, it is better to use subqueries in SELECT statements. When configuring the data source, there is an easy way to make our lives better:</p>
<p>1. Use a SELECT statement on one table.</p>
<p>2. Click &#8216;Advanced&#8217; tab and Check &#8216;Automatically Generate INSERT, UPDATE, DELETE statements&#8217;.</p>
<p>Now Configure the same datasource again. Now use 1or more SELECT subqueries within the original subquery.</p>
<p>This would give us the same desired result like using JOINs. Also, INSERT, UPDATE, DELETE statements aer automatically generated for us.</p>
<p>SQL QUERY USING JOINS:</p>
<p><strong>USE NORTHWIND<br />
</strong></p>
<p><strong>SELECT TOP 5 PDT.PRODUCTNAME, CAT.CATEGORYNAME, SUP.COMPANYNAME FROM CATEGORIES CAT<br />
INNER JOIN PRODUCTS PDT ON CAT.CATEGORYID=PDT.CATEGORYID<br />
INNER JOIN SUPPLIERS SUP ON SUP.SUPPLIERID = PDT.SUPPLIERID</strong></p>
<p>Now the same result can be produced using the below SQL query:</p>
<p><strong>USE NORTHWIND</strong></p>
<p><strong>SELECT TOP 5 PRODUCTNAME,<br />
(SELECT CATEGORYNAME FROM CATEGORIES WHERE CATEGORIES.CATEGORYID=PRODUCTS.CATEGORYID) AS CATEGORYNAME,<br />
(SELECT COMPANYNAME FROM SUPPLIERS WHERE SUPPLIERS.SUPPLIERID = PRODUCTS.SUPPLIERID) AS SUPPLIERNAME<br />
FROM PRODUCTS</strong></p>
<p>Reference: Scott Mitchell&#8217;s Data Access Tutorials in www.asp.net</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=14&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/07/04/join-in-datasets-good-idea-or-bad-idea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>GridView and DataSource</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/07/04/gridview-and-datasource/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/07/04/gridview-and-datasource/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 21:03:36 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[dataset]]></category>
		<category><![CDATA[Gridview]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=13</guid>
		<description><![CDATA[GridView is built to work with DataSource. This DataSource can be either dataset or a DataSource control.
When using GV with DSet, you have to handle the Paging, Editing, Sorting functions.
When using GV with DSrc, the above functions are built-in for you. If you have a strict 3-tier architecture, use ObjectDataSource control.
Suppose I don&#8217;t use a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=13&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>GridView is built to work with DataSource. This DataSource can be either dataset or a DataSource control.</p>
<p>When using GV with DSet, you have to handle the Paging, Editing, Sorting functions.</p>
<p>When using GV with DSrc, the above functions are built-in for you. If you have a strict 3-tier architecture, use ObjectDataSource control.</p>
<p>Suppose I don&#8217;t use a primary key column in the SELECT statement for SqlDataSource. What would happen in that case?</p>
<p>I tried it and in the UPDATE command i set the condition to check for a specific primary key value but the catch is there is no PK in SELECT statement. When I tried to run this code, I didn&#8217;t get any error. I was able to click &#8216;EDIT&#8217; button of GridView, enter new information and UPDATE it. However the thing is no info was updated. It didn&#8217;t show any error but it didnt give the desired result either.</p>
<p>So have one column as PK. If you didn&#8217;t select any PK column, at least set the DataKeys value to a column name. This way the column will be made a PK column for the datatable.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=13&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/07/04/gridview-and-datasource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
		<item>
		<title>DataSet Editing</title>
		<link>http://myexperimentswithcode.wordpress.com/2008/06/30/dataset-editing/</link>
		<comments>http://myexperimentswithcode.wordpress.com/2008/06/30/dataset-editing/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 20:50:51 +0000</pubDate>
		<dc:creator>vijeyashobana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[AcceptChanges]]></category>
		<category><![CDATA[BeginEdit]]></category>
		<category><![CDATA[datarow]]></category>
		<category><![CDATA[dataset]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://myexperimentswithcode.wordpress.com/?p=11</guid>
		<description><![CDATA[It seems so easy to say the data in dataset can be edited and updated to the database. But in reality there are abundant problems surrounding this single concept. This is because there are numerous different situations pertaining to this simple concept. Some are, what if the underlying table has no primary key? what if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=11&subd=myexperimentswithcode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It seems so easy to say the data in dataset can be edited and updated to the database. But in reality there are abundant problems surrounding this single concept. This is because there are numerous different situations pertaining to this simple concept. Some are, what if the underlying table has no primary key? what if the underlying table is a result of join on 2 different tables?  what if the underlying table does have a primary key? Will the dataset created in a Button_Click be carried over to the other events of the gridview/ any databound control for that matter? What about AcceptChanges(), BeginEdit()?</p>
<p>We will analyze every question one by one here.</p>
<p>what if the underlying table has no primary key?<strong> </strong></p>
<p>if the dataTable of Dataset has no PK , manually set a PK on any column of the dataTable.</p>
<p><strong>dset.Tables[0].PrimaryKey = new System.Data.DataColumn[] { dset.Tables[0].Columns[1] };</strong></p>
<p>To have more than 1 column as a PK, i.e, composite PK, use :</p>
<p><strong>dset.Tables[0].PrimaryKey = new System.Data.DataColumn[] { dset.Tables[0].Columns[1] , </strong><strong>dset.Tables[0].Columns[2]</strong><strong>};</strong></p>
<p><strong></strong><br />
Remember, PrimaryKey property returns a DataColumn[]. So you need to set a DataColumn array value to it otherwise it throws an error.</p>
<p>what if the underlying table is a result of join on 2 different tables?</p>
<p>if the Dtbl is a result of join, then the DataTable will not have any PK on it. In this case, you have to manually set it.</p>
<p>what if the underlying table does have a primary key?</p>
<p>This usually happens if the DataTable is a result of some SELECT statement and the SELECT statement gives a column set as PK. So in this case, we have to make sure the CONSTRAINTS info is updated in the dataset. This is because when you call a SELECT  statement, the schema info is not added to the dataset. It should be done manually thus:</p>
<p><strong>da.FillSchema(dset, SchemaType.Source, &#8220;Authors&#8221;); </strong></p>
<p>if you didn&#8217;t use the above statement, you can also use the below one:</p>
<p><strong>da.MissingSchemaAction = MissingSchemaAction.AddWithKey;</strong></p>
<p>If you manually set the PK on the underlying DaTbl, donot use the above code. If you use both, it will throw exception.</p>
<p>Will the dataset created in a Button_Click be carried over to the other events of the gridview/ any databound control for that matter?</p>
<p>No. the dset will not be carried over. So you have to have a method to fill the dataset and call that method in your other DataBound events.</p>
<p>What about AcceptChanges(), Begin/EndEdit()?</p>
<p>To make changes in any DataRow, I need to create a new DataRow. But I cannot use DataRow() because this cannot be used. You need to use</p>
<p><strong>DataRow dr = dt.NewRow();</strong></p>
<p>and assign the dr with the required row, <strong></strong></p>
<p><strong>dr = dt.Rows.Find(&#8220;Aria Cruz&#8221;);</strong></p>
<p>Following the above,</p>
<p><strong> dr.BeginEdit();</strong><br />
<strong>dr["EMPLOYEE_NAME"] = &#8220;Aria Tamil&#8221;; //changed the original name to Aria Tamil<br />
dr.EndEdit();<br />
dset.AcceptChanges();</strong> //committing the dataset with the changes<br />
<strong>da.Update(dset);</strong> //pass the changed dataset to d/b</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/myexperimentswithcode.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/myexperimentswithcode.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/myexperimentswithcode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/myexperimentswithcode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/myexperimentswithcode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/myexperimentswithcode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/myexperimentswithcode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/myexperimentswithcode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/myexperimentswithcode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/myexperimentswithcode.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/myexperimentswithcode.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/myexperimentswithcode.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=myexperimentswithcode.wordpress.com&blog=4086417&post=11&subd=myexperimentswithcode&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://myexperimentswithcode.wordpress.com/2008/06/30/dataset-editing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaa7928b428fe864809960f79c9b2fcd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vijeyashobana</media:title>
		</media:content>
	</item>
	</channel>
</rss>