<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>explore.net</title>
	<atom:link href="http://nisanthvijay.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nisanthvijay.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 12 Dec 2011 10:18:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nisanthvijay.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/f7d715063bfbb308fa75fbfcb308e2af?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>explore.net</title>
		<link>http://nisanthvijay.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nisanthvijay.wordpress.com/osd.xml" title="explore.net" />
	<atom:link rel='hub' href='http://nisanthvijay.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Aborting Combobox Dropdown</title>
		<link>http://nisanthvijay.wordpress.com/2011/11/17/aborting-combobox-dropdown/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/11/17/aborting-combobox-dropdown/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 06:22:30 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1208</guid>
		<description><![CDATA[In my windows application i need to aborting the Combox dropdown in some case, Just how do you tell the combo box that you don’t actually want it to drop down? I was hoping the DropDown event would take a CancelEventArgs, but nope — and not surprising, since after a little digging, I finally got it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1208&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my windows application i need to aborting the Combox dropdown in some case, Just how do you tell the combo box that you don’t actually want it to drop down?</p>
<p>I was hoping the DropDown event would take a CancelEventArgs, but nope — and not surprising, since after a little digging, I finally got it to work,  Here’s the code:<a href="http://nisanthvijay.files.wordpress.com/2011/11/cancel_dropdown1.jpg"><img class="alignnone size-full wp-image-1213" title="Cancel_Dropdown" src="http://nisanthvijay.files.wordpress.com/2011/11/cancel_dropdown1.jpg" alt="" width="939" height="412" /></a></p>
<p>Happy Coding <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1208&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/11/17/aborting-combobox-dropdown/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/11/cancel_dropdown1.jpg" medium="image">
			<media:title type="html">Cancel_Dropdown</media:title>
		</media:content>
	</item>
		<item>
		<title>Siri : &#8211; A Powerful Virtual Assistant For The iPhone</title>
		<link>http://nisanthvijay.wordpress.com/2011/11/11/siri-a-powerful-virtual-assistant-for-the-iphone/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/11/11/siri-a-powerful-virtual-assistant-for-the-iphone/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 10:55:19 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[Non Techanical]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1196</guid>
		<description><![CDATA[Siri (pronounced /ˈsɪri/) is a personal assistant application for iOS. The application uses natural language processing to answer questions, make recommendations, and perform actions by delegating requests to an expanding set of web services. Siri claims that the software adapts to the user&#8217;s individual preferences over time and personalizes results, as well as accomplishing tasks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1196&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a class="zem_slink" title="Siri" href="http://www.siri.com/" rel="homepage">Siri</a> (pronounced /ˈsɪri/) is a personal assistant application for iOS. The application uses natural language processing to answer questions, make recommendations, and perform actions by delegating requests to an expanding set of web services. Siri claims that the software adapts to the user&#8217;s individual preferences over time and personalizes results, as well as accomplishing tasks such as making dinner reservations and reserving a cab.</p>
<p>Siri was originally introduced as an iOS application available in the AppStore. Siri was acquired by Apple Inc. on April 28, 2010. Siri had announced that their software would be available for BlackBerry and for Android-powered phones, but all development efforts for non-Apple platforms were cancelled after Apple&#8217;s purchase.</p>
<p>Siri is now an integrated part of iOS 5, and available only on the iPhone 4S, launched in October 2011.</p>
<p>Independent developers claim that they ported Siri to iPhone 4.However, some news sites consider that the videos they posted for proof only show the User interface of the application, excluding any voice commands, to conclude that they did not prove anything. However, new sources suggests that the independent developers are able to port Siri to the iPhone 4 and the iPod Touch.</p>
<p><a href="http://nisanthvijay.files.wordpress.com/2011/11/siri.jpg"><img title="Siri" src="http://nisanthvijay.files.wordpress.com/2011/11/siri.jpg?w=274&#038;h=676" alt="" width="274" height="676" /></a></p>
<p>From Wikipedia</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1196/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1196&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/11/11/siri-a-powerful-virtual-assistant-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/11/siri.jpg" medium="image">
			<media:title type="html">Siri</media:title>
		</media:content>
	</item>
		<item>
		<title>Making Database to Read Only – Changing Database to Read/Write</title>
		<link>http://nisanthvijay.wordpress.com/2011/07/18/making-database-to-read-only-%e2%80%93-changing-database-to-readwrite/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/07/18/making-database-to-read-only-%e2%80%93-changing-database-to-readwrite/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 05:21:35 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1167</guid>
		<description><![CDATA[If you face error that if database is already in use, you can resolve the same by making database in single user mode – here is the guideline ALTER DATABASE [YourDbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; The above query will rollback any transaction which is running on that database and brings SQL Server database in a single [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1167&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://nisanthvijay.files.wordpress.com/2011/04/dbread.jpg"><img class="alignnone size-full wp-image-1168" title="DBRead" src="http://nisanthvijay.files.wordpress.com/2011/04/dbread.jpg" alt="" width="370" height="229" /></a></p>
<p>If you face error that if database is already in use, you can resolve the same by making database in single user mode – here is the guideline</p>
<p><code><span style="color:#0000ff;">ALTER DATABASE</span> [YourDbName]<br />
<span style="color:#0000ff;">SET</span> SINGLE_USER <span style="color:#0000ff;">WITH ROLLBACK</span> IMMEDIATE;</code></p>
<p>The above query will rollback any transaction which is running on that database and brings SQL Server database in a single user mode.</p>
<p>The usual error due to database in use is as follows:</p>
<p><span style="color:#ff0000;">Msg 3702, Level 16, State 3, Line 1</span><br />
<span style="color:#ff0000;">Cannot drop database “YourDbName” because it is currently in use.</span></p>
<p>as the ALTER script mentioned on the top of the post will remove that error. Please make sure that if you are on production server, alter database should be used very carefully.</p>
<p>Reference : <strong>Pinal Dave </strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1167&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/07/18/making-database-to-read-only-%e2%80%93-changing-database-to-readwrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/04/dbread.jpg" medium="image">
			<media:title type="html">DBRead</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with images in Reporting Services</title>
		<link>http://nisanthvijay.wordpress.com/2011/06/28/working-with-images-in-reporting-services/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/06/28/working-with-images-in-reporting-services/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 04:40:15 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1071</guid>
		<description><![CDATA[Images. They can make your reports look great, but sometimes they are a bit tricky to show where you want, and when you want. Even something as simple as showing an image or not, or showing a different image based on the condition of some data. Well, it might not be rocket science (or rocket [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1071&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Images. They can make your reports look great, but sometimes they are a bit tricky to show where you want, and when you want. Even something as simple as showing an image or not, or showing a different image based on the condition of some data.</p>
<p>Well, it might not be rocket science (or rocket engineering) but its not exactly well documented, so here are a couple of real world examples of how to handle images in your reports.</p>
<h2>Showing/Hiding Images</h2>
<p>First of all this is how to show or hide an image in a table, based on the condition of filed in your data set. This could be used to indicate (for instance) if an order is stopped. The first thing to do is add an image holder into your table. When you drag the image holder onto the cell of the table the image wizard will open. Follow the Wizard through and embed the image in your report. When its done you will see the image in the table cell.</p>
<p>Now, on the properties of the cell, drop down the <em>Visible -&gt; Hidden</em> property, and click in<em>Expression</em> in the list, this will open up the expression editor. In here we are going to use an <a title="IIF Statment Wikipedia" href="http://en.wikipedia.org/wiki/IIf" target="_blank">IIF </a>statement to check the condition of one of our fields. We can then set the<em>Visible </em>state to <em>true </em>or <em>false </em>depending on the outcome. The statement will look something like:</p>
<p><em>=iif(Fields!Stop_Stat.Value = “Stop”, False, True)</em></p>
<p>With this now in place, when you run the report it should now only show the image when the value of Stop_Stat is true.</p>
<h2>Changing the Image</h2>
<p>The will be some circumstances where you want to show a different image depending on the value of a variable. This is done in a similar way to hiding the image, but instead you<em>Data</em> value of the image source.</p>
<p>The first thing to do is insert the images you need onto the report. Drop an image control onto your table where you want it to apear, and embed the image into the report. Then drop another image control on the report, maybe in the header or somewhere out of the way. Embed the image again and this time set this controls<em>Visible </em>property to false. Now you have both the images you need in the report.</p>
<p>At this point make a note of the names of both of the images embedded in the report. They tend to be the name of the file you used without the extension.</p>
<p>Now, go into the property’s of the image control in the table, under <em>Data -&gt; Value </em>drop down to <em>Expression</em> to open up the expression editor. Here we are going to use an IIF statement on a filed, and tell it to use one image if the condition is true, or a different one if it was false:</p>
<p><em>=iif(Fields!Stop_date.Value is nothing, “advert_incomplete_1″, “stop”)</em></p>
<p>When you save it you wont see the image in the box any more, it should have changed to this</p>
<p><img src="http://www.beakersoft.co.uk/img/image_expresion.gif" alt="Image with expresion" align="middle" /></p>
<p>Now, when you run the report, the images should swap round depending on what the value of your filed is, so you will end up with something like</p>
<p><img src="http://www.beakersoft.co.uk/img/image_expresion_example.gif" alt="image expresion example" align="middle" /></p>
<p>Hopefully, you should now be able to make better use of images in your reports now, making them a bit better to look at and by using visual pointers instead of plain old text.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1071/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1071&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/06/28/working-with-images-in-reporting-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://www.beakersoft.co.uk/img/image_expresion.gif" medium="image">
			<media:title type="html">Image with expresion</media:title>
		</media:content>

		<media:content url="http://www.beakersoft.co.uk/img/image_expresion_example.gif" medium="image">
			<media:title type="html">image expresion example</media:title>
		</media:content>
	</item>
		<item>
		<title>Insert Data From One Table to Another Table Using INSERT or SELECT</title>
		<link>http://nisanthvijay.wordpress.com/2011/04/11/insert-data-from-one-table-to-another-table-using-insert-or-select/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/04/11/insert-data-from-one-table-to-another-table-using-insert-or-select/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 04:42:32 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1131</guid>
		<description><![CDATA[This post answer three Question How to insert data from one table to another table efficiently? How to insert data from one table using where condition to anther table? How can I stop using cursor to move data from one table to another table? There are two different ways to implement inserting data from one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1131&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post answer three Question</p>
<ul>
<li><span style="color:#008000;"><em>How to insert data from one table to another table efficiently?</em></span></li>
<li><span style="color:#008000;"><em>How to insert data from one table using where condition to anther table?</em></span></li>
<li><span style="color:#008000;"><em>How can I stop using cursor to move data from one table to another table?</em></span></li>
</ul>
<p>There are two different ways to implement inserting data from one table to another table. I strongly suggest to use either of the method over cursor. Performance of following two methods is far superior over cursor. I prefer to use Method 1 always as I works in all the case.</p>
<p><strong>Method 1 : INSERT INTO SELECT</strong><br />
This method is used when table is already created in the database earlier and data is to be inserted into this table from another table. If columns listed in insert clause and select clause are same, they are are not required to list them. I always list them for readability and scalability purpose.</p>
<p><a href="http://nisanthvijay.files.wordpress.com/2011/03/insert.jpg"><img class="alignnone size-full wp-image-1132" title="Insert" src="http://nisanthvijay.files.wordpress.com/2011/03/insert.jpg" alt="" width="510" height="291" /></a><br />
<strong>Method 2 : SELECT INTO </strong><br />
This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.<br />
<a href="http://nisanthvijay.files.wordpress.com/2011/03/select.jpg"><img class="alignnone size-full wp-image-1133" title="Select" src="http://nisanthvijay.files.wordpress.com/2011/03/select.jpg" alt="" width="495" height="247" /></a><br />
Both of the above method works with database temporary tables (global, local).</p>
<div><em> </em></div>
<div><em> </em></div>
<p><em> </p>
<p></em></p>
<p><em> </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1131&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/04/11/insert-data-from-one-table-to-another-table-using-insert-or-select/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/03/insert.jpg" medium="image">
			<media:title type="html">Insert</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/03/select.jpg" medium="image">
			<media:title type="html">Select</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Retrieve TOP and BOTTOM Rows Together</title>
		<link>http://nisanthvijay.wordpress.com/2011/04/01/how-to-retrieve-top-and-bottom-rows-together/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/04/01/how-to-retrieve-top-and-bottom-rows-together/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 07:10:23 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1144</guid>
		<description><![CDATA[Just a day ago, while working with some inventory related projects, I faced one interesting situation. I had to find TOP 1 and BOTTOM 1 record together. I right away that I should just do UNION but then I realize that UNION will not work as it will only accept one ORDER BY clause. If [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1144&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Just a day ago, while working with some inventory related projects, I faced one interesting situation. I had to find TOP 1 and BOTTOM 1 record together. I right away that I should just do UNION but then I realize that UNION will not work as it will only accept one ORDER BY clause. If you specify more than one ORDER BY clause. It will give error.</p>
<p style="text-align:justify;">Incorrect T-SQL Script which will give error.<br />
USE AdventureWorks<br />
GO<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">SELECT TOP</span></span> 1 SalesOrderDetailID<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">FROM</span></span> Sales.SalesOrderDetail<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">ORDER BY</span></span> SalesOrderDetailID<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">UNION</span></span> ALL<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">SELECT TOP</span></span> 1 SalesOrderDetailID<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">FROM </span></span>Sales.SalesOrderDetail<br />
<span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">ORDER BY </span></span>SalesOrderDetailID <span style="color:blue;"><span style="font-size:x-small;font-family:Courier New;">DESC</span></span><br />
GO<br />
ResultSet:<br />
<span style="color:#ff0000;">Msg 156, Level 15, State 1, Line 4<br />
Incorrect syntax near the keyword ‘UNION’. </span></p>
<p style="text-align:justify;">As I was in rush, I wrote something very simple with using UNION code, which will give me similar result.</p>
<p style="text-align:justify;">Correct SQL Script which will give correct output.</p>
<p style="text-align:justify;"><strong>Correct Script Method 1:</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">SalesOrderDetailID </span><span style="color:blue;">IN </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">1 </span><span style="color:blue;">MIN</span><span style="color:gray;">(</span><span style="color:black;">SalesOrderDetailID</span><span style="color:gray;">) </span><span style="color:black;">SalesOrderDetailID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">1 </span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">SalesOrderDetailID</span><span style="color:gray;">) </span><span style="color:black;">SalesOrderDetailID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<img src="http://www.pinaldave.com/blogfolder/unionall.gif" alt="" width="496" height="331" /></p>
<p style="text-align:justify;"><strong>Correct Script Method 2:</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">SalesOrderDetailID </span><span style="color:blue;">IN </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">1 SalesOrderDetailID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">SalesOrderDetailID</span><span style="color:gray;">)<br />
OR<br />
</span><span style="color:black;">SalesOrderDetailID </span><span style="color:blue;">IN </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">1 SalesOrderDetailID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Sales.SalesOrderDetail<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">SalesOrderDetailID </span><span style="color:blue;">DESC</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<img src="http://www.pinaldave.com/blogfolder/unionall1.gif" alt="" width="355" height="360" /></p>
<p style="text-align:justify;"><strong>Correct Script Method 3:<br />
</strong><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">(<span style="color:blue;">SELECT </span><span style="color:#0000ff;">TOP </span>1 *<br />
<span style="color:blue;">FROM </span>Sales.SalesOrderDetail<br />
<span style="color:blue;">ORDER BY </span>SalesOrderDetailID<br />
)X1</span><span style="color:gray;"><br />
<span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span></span><span style="color:black;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">(<span style="color:blue;">SELECT </span><span style="color:#0000ff;">TOP </span>1 *<br />
<span style="color:blue;">FROM </span>Sales.SalesOrderDetail<br />
<span style="color:blue;">ORDER BY </span>SalesOrderDetailID<br />
</span></span><span style="color:blue;">DESC</span><span style="color:gray;">)X2<br />
</span><span style="color:black;">GO</span></code></p>
<div id="_mcePaste" class="mcePaste" style="left:-10000px;overflow:hidden;width:1px;position:absolute;top:0;height:1px;">﻿</div>
<p>WITH TopBottomRow<br />
AS<br />
(<br />
<span style="font-family:Courier New;"><span style="color:blue;">SELECT </span><span style="color:#0000ff;">TOP </span>1 *<br />
<span style="color:blue;">FROM </span>Sales.SalesOrderDetail<br />
<span style="color:blue;">ORDER BY </span>SalesOrderDetailID</span><br />
<span style="color:blue;"><span style="font-family:Courier New;">UNION </span></span><span style="color:gray;"><span style="font-family:Courier New;">ALL</span><br />
</span><span style="font-family:Courier New;"><span style="color:blue;">SELECT </span><span style="color:#0000ff;">TOP </span>1 *<br />
<span style="color:blue;">FROM </span>Sales.SalesOrderDetail<br />
<span style="color:blue;">ORDER BY </span>SalesOrderDetailID<br />
<span style="color:blue;">DESC</span></span>)<br />
<span style="color:blue;"><span style="font-family:Courier New;">SELECT </span></span>*<br />
<span style="color:blue;"><span style="font-family:Courier New;">FROM </span></span>TopBottomRow</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1144&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/04/01/how-to-retrieve-top-and-bottom-rows-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/unionall.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/unionall1.gif" medium="image" />
	</item>
		<item>
		<title>Insert Multiple Records Using One Insert Statement</title>
		<link>http://nisanthvijay.wordpress.com/2011/03/15/insert-multiple-records-using-one-insert-statement/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/03/15/insert-multiple-records-using-one-insert-statement/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 04:54:09 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1135</guid>
		<description><![CDATA[How can I insert multiple values in table using only one insert? Now this is interesting question. When there are multiple records are to be inserted in the table following is the common way using T-SQL. Method 1   Method 2 The clause INSERT INTO is repeated multiple times. Many times DBA copy and paste [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1135&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How can I insert multiple values in table using only one insert? Now this is interesting question. When there are multiple records are to be inserted in the table following is the common way using T-SQL.</p>
<p><strong>Method 1</strong></p>
<p><a href="http://nisanthvijay.files.wordpress.com/2011/03/insert2.jpg"><img class="alignnone size-full wp-image-1137" title="Insert" src="http://nisanthvijay.files.wordpress.com/2011/03/insert2.jpg" alt="" width="425" height="269" /></a> </p>
<p><strong>Method 2</strong></p>
<p>The clause INSERT INTO is repeated multiple times. Many times DBA copy and paste it to save time. There is another alternative to this, which I use frequently. I use UNION ALL and INSERT INTO … SELECT… clauses. Regarding performance there is not much difference. If there is performance difference it does not matter as I use this for one time insert script. I enjoy writing this way, as it keeps me focus on task, instead of copy paste.</p>
<p><a href="http://nisanthvijay.files.wordpress.com/2011/03/insert11.jpg"><img class="alignnone size-full wp-image-1138" title="Insert1" src="http://nisanthvijay.files.wordpress.com/2011/03/insert11.jpg" alt="" width="427" height="273" /></a></p>
<p><strong>Method 3</strong></p>
<p>In SQL Server 2008 we have new feature which will make our life much more easier.</p>
<p><a href="http://nisanthvijay.files.wordpress.com/2011/03/insert3.jpg"><img class="alignnone size-full wp-image-1139" title="Insert3" src="http://nisanthvijay.files.wordpress.com/2011/03/insert3.jpg" alt="" width="344" height="154" /></a></p>
<p>The effective result is same.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1135&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/03/15/insert-multiple-records-using-one-insert-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/03/insert2.jpg" medium="image">
			<media:title type="html">Insert</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/03/insert11.jpg" medium="image">
			<media:title type="html">Insert1</media:title>
		</media:content>

		<media:content url="http://nisanthvijay.files.wordpress.com/2011/03/insert3.jpg" medium="image">
			<media:title type="html">Insert3</media:title>
		</media:content>
	</item>
		<item>
		<title>Text Included into DataGridViewCheckBoxCell</title>
		<link>http://nisanthvijay.wordpress.com/2011/02/25/text-included-into-datagridviewcheckboxcell/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/02/25/text-included-into-datagridviewcheckboxcell/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 07:24:09 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[C#.Net]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1111</guid>
		<description><![CDATA[A few weeks ago, my friend handed me requirements for a WinForms project. One of the screenshots that the friend painstakingly created using some graphics program consisted of a grid that included a checkbox column. The jarring thing about this checkbox column was that each cell in the column also included some text. Since the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1111&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, my friend handed me requirements for a WinForms project. One of the screenshots that the friend painstakingly created using some graphics program consisted of a grid that included a checkbox column. The jarring thing about this checkbox column was that each cell in the column also included some text. Since the <em>DataGridView</em> control doesn’t come “out of the box” with a combination Checkbox/Text type column, my initial reflex reaction was to suggest that we either change our approach, or look into third party products. However, before going down that road, I decided to try to create one. So I tried, it worked, and we all lived happily ever after. Here’s the approach:</p>
<p>Since I was going to all this trouble (which actually turned out to be pretty easy), I decided I should make this thing as configurable as possible. Rather than hard-code it according to my friends specific requirements, I decided to include the following properties: “Text”, “Color”, “Font”, and “Enabled”, so that it would be flexible enough should this friends needs change (and so I could use it in other projects in the future).</p>
<p>To start out with, we need to extend not only the <em>DataGridViewCheckBoxCell</em> class, but the <em>DataGridViewCheckBoxColumn</em> class as well. I called my new classes <strong>DataGridViewCheckAndTextColumn</strong> and <strong>DataGridViewCheckAndTextCell</strong>. Here’s how we’ll start:</p>
<div>public class DataGridViewCheckAndTextColumn : DataGridViewCheckBoxColumn<br />
{<br />
    public DataGridViewCheckAndTextColumn()<br />
    {<br />
        this.CellTemplate = new DataGridViewCheckAndTextCell();<br />
    }<br />
}</div>
<p>public class DataGridViewCheckAndTextCell : DataGridViewCheckBoxCell<br />
{<br />
    public DataGridViewCheckAndTextCell()<br />
    {<br />
        this.Enabled = true;<br />
    }</p>
<p>    private bool enabled;<br />
    public bool Enabled<br />
    {<br />
        get<br />
        {<br />
            return enabled;<br />
        }<br />
        set<br />
        {<br />
            enabled = value;<br />
            this.ReadOnly = !enabled;<br />
        }<br />
    }</p>
<p>    private string text;<br />
    public string Text<br />
    {<br />
        get { return text; }<br />
        set { text = value; }<br />
    }</p>
<p>    private System.Drawing.Color color;<br />
    public System.Drawing.Color Color<br />
    {<br />
        get<br />
        {<br />
            return color;<br />
        }<br />
        set { color = value; }<br />
    }</p>
<p>    private System.Drawing.Font font;<br />
    public System.Drawing.Font Font<br />
    {<br />
        get { return font; }<br />
        set { font = value; }<br />
    }<br />
}</p>
<p>Note that the <strong>DataGridViewCheckAndTextColumn</strong> class contains a constructor which tells it that its cells will be of type <strong>DataGridViewCheckAndTextCell</strong>. And, the <strong>DataGridViewCheckAndTextCell</strong> class itself contains the properties I mentioned earlier, in addition to a constructor which sets the Enabled property to True by default.</p>
<p>Next, we’re going to override the <em>DataGridViewCheckBoxCell</em>’s <em>Paint()</em> method. Within our version of the <em>Paint() </em>method, we will first call the base class’s (<em>DataGridViewCheckBoxCell</em>’s) <em>Paint()</em> method, and then do some work of our own. We call the base class’s <em>Paint()</em> method so that it can do whatever other stuff it normally does (we don’t necessarily need to know what that “other stuff” might consist of – isn’t inheritance wonderful?), and then we do what we need to do to make our class work the way we want it to. Here’s the code. Explanations follow:</p>
<p>protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,<br />
    int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue,<br />
    string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,<br />
    DataGridViewPaintParts paintParts)<br />
{<br />
    base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value,<br />
        formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);</p>
<p>    if (this.Font == null)<br />
        this.Font = cellStyle.Font;</p>
<p>    if (!this.Enabled)<br />
        this.Color = Color.Gray;<br />
    else if (this.Color.IsEmpty)<br />
        this.Color = cellStyle.ForeColor;</p>
<p>    CheckBoxState state;<br />
    bool val = this.Value == null || !Convert.ToBoolean(this.Value) ? false : Convert.ToBoolean(this.Value);<br />
    if (this.enabled &amp;&amp; val)<br />
        state = CheckBoxState.CheckedNormal;<br />
    else if (this.enabled &amp;&amp; !val)<br />
        state = CheckBoxState.UncheckedNormal;<br />
    else if (!this.enabled &amp;&amp; val)<br />
        state = CheckBoxState.CheckedDisabled;<br />
    else<br />
        state = CheckBoxState.UncheckedDisabled;</p>
<p>    Point loc = new Point(cellBounds.X + 2, cellBounds.Y + 2);<br />
    //CheckBoxRenderer.DrawCheckBox(graphics, loc, state);</p>
<p>    Rectangle contentBounds = this.GetContentBounds(rowIndex);<br />
    Point stringLocation = new Point();<br />
    stringLocation.Y = cellBounds.Y + 2;<br />
    stringLocation.X = cellBounds.X + contentBounds.Right + 2;<br />
    graphics.DrawString(this.Text, this.Font, new SolidBrush(this.Color), stringLocation);<br />
}</p>
<p>The first thing you’ll notice (after the call to <em>base.Paint()</em> ) is that we’re checking the values of our properties, and taking appropriate actions. First, we check to see whether the calling code has set a value for <em>this.Font</em>. If that property is null (the property hasn’t been set), we’ll take the default Font (passed in to the <em>Paint()</em> method by the <em>DataGridView</em> control) and use that as our font. Next, we check to see if the <em>Enabled</em> property is set to true or false. If <em>Enabled</em> is false, we’re going to set <em>this.Color</em> to gray, no matter what the <em>Color</em> property says. Otherwise, if the property has not been set, we’ll use the default color passed in to the <em>Paint()</em> method by the <em>DataGridView</em> control. And lastly, if the property was set by the calling code and <em>Enabled</em> is true, we do nothing at this point, and use <em>this.Color</em> as the calling code intended.</p>
<p>Next we set the state of the checkbox. There are four possible values from the <em>CheckBoxState</em> enumerator for our purposes: <em>CheckedNormal</em>, <em>UncheckedNormal</em>, <em>CheckedDisabled</em>, and <em>UncheckedDisabled</em>. We set the state variable based on the underlying value of the data in the cell, combined with the <em>this.Enabled</em> property value.</p>
<p>Now that all of our properties and variables have been set, we’ll put them to work. First, we determine our starting point, based on the cell boundaries. We pass the <em>cellBounds</em> variable passed into the <em>Paint()</em> method to instantiate a <em>Point</em> object (<em>loc</em>), adding 2 pixels top and left to create a little margin. Once we have our starting <em>loc</em>ation, we can use it, along with our <em>state</em> variable and the <em>graphics</em> object passed in to <em>Paint()</em>, to render a checkbox exactly where we want it within the cell (all the way to the left so that there’s room for the text we’re going to add).</p>
<p>Now we’re ready to draw the text. First, we get a <em>Rectangle</em> object, <em>contentBounds</em>, based on the <em>rowIndex</em> which is also passed in to the <em>Paint()</em> method. ( I told you this was easy!) Next, we instaniate a <em>Point</em> object (<em>stringLocation</em>). Its <em>X</em> coordinate will be 2 pixels to the right of the checkbox, and its <em>Y</em> coordinate will be 2 pixels down from the top of the cell. Then we draw a string beginning at that location. We do that by calling the <em>DrawString()</em> method on the <em>graphics</em> object. The method takes four parameters; the string to draw (for which we use the value in <em>this.Text</em> which gets set by the calling code), the font (<em>this.Font</em>), the color (<em>this.Color</em>), and of course, the location (<em>stringLocation</em>).</p>
<p>Believe it or not, that’s all there is to it. You can use your new masterpiece just like you would use any other type of <em>DataGridView</em> column. It’ll even show up in the designer for you:</p>
<p><img src="http://www.murrayhilltech.com/images/datagridviewcheckandtext.png" alt="" width="829" height="512" /></p>
<p>And the calling code will look something like this:</p>
<p>private void grid1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)<br />
{<br />
    DataGridViewCheckAndTextCell ctCell = null;<br />
    foreach (DataGridViewRow row in grid1.Rows)<br />
    {<br />
        if (row != null)<br />
        {<br />
            ctCell = row.Cells["CheckAndText"] as DataGridViewCheckAndTextCell;<br />
            if (ctCell != null)<br />
            {<br />
                ctCell.Enabled = true;<br />
                ctCell.Text = &#8220;Hello!&#8221;;<br />
                ctCell.Color = Color.Blue;<br />
            }<br />
        }<br />
    }<br />
}</p>
<p>Here’s a screenshot of the final product:</p>
<p><img src="http://www.murrayhilltech.com/images/multicolumnheader.png" alt="" /></p>
<p>Enjoy ..!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1111&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/02/25/text-included-into-datagridviewcheckboxcell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://www.murrayhilltech.com/images/datagridviewcheckandtext.png" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/multicolumnheader.png" medium="image" />
	</item>
		<item>
		<title>Creating A Multiple Column Header Within DataGridView</title>
		<link>http://nisanthvijay.wordpress.com/2011/02/11/creating-a-multiple-column-header-within-datagridview/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/02/11/creating-a-multiple-column-header-within-datagridview/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 03:13:28 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[C#.Net]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1108</guid>
		<description><![CDATA[I had a need to create a grid with a column header that spanned four columns. Having done a lot of ASP.Net in the past (and HTML directly in the more distant past), and knowing that this is a very simple thing to do in that environment, I figured it would be just as simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1108&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had a need to create a grid with a column header that spanned four columns. Having done a lot of ASP.Net in the past (and HTML directly in the more distant past), and knowing that this is a very simple thing to do in that environment, I figured it would be just as simple in the WinForms environment using the DataGridView. As happens far more often than I’d like to admit, I was wrong, although not by much. It wasn’t as simple as I had hoped, but it really wasn’t all that bad. Read on:</p>
<p>Basically, all we need to do is handle the DataGridView’s Paint() event. Let’s say we want to span columns 3, 4, 5, and 6 with one header that says “My Big Header”. Within the Paint() event handler, we’ll get a handle to the header cell of the first column you wish to span (“Column 3”), and we’ll use that to determine the coordinates of the location on the grid at which we will begin our header text:</p>
<p><span style="color:#339966;">DataGridViewCell hc = grid1.Columns[“Column 3”].HeaderCell;</span><br />
<span style="color:#339966;">Rectangle hcRct = grid1.GetCellDisplayRectangle(hc.ColumnIndex, -1, true);</span></p>
<p>The first line of code should be self-explanatory. In the second line, we’re getting a <em>Rectangle</em> object based on the cell in question. Passing the column index and the row index (“-1” means the row header) to the <em>DataGridView</em>’s <em>GetCellDisplayRectangle()</em> method gets us there.</p>
<p>Next, we’ll use that <em>Rectangle</em> object to get another <em>Rectangle</em> that represents the entire area to be covered by our new Multi-Column-Header. We can do that like so:</p>
<p><span style="color:#339966;">int multiHeaderWidth = grid1.Columns[hc.ColumnIndex].Width + grid1.Columns[hc.ColumnIndex + 1].Width + grid1.Columns[hc.ColumnIndex + 2].Width + grid1.Columns[hc.ColumnIndex + 3].Width;</span></p>
<p><span style="color:#339966;">Rectangle headRct = new Rectangle(hcRct.Left, hc.ContentBounds.Y + 2, multiHeaderWidth, grid1.ColumnHeadersHeight);</span></p>
<p><span style="color:#339966;">headRct.Height -= 3;</span></p>
<p>As you can see, the first line above simply gets the total width of all four columns to be spanned. We then pass that variable along with the other three coordinates (left, top, and height) required to instantiate a <em>Rectangle</em> object. (We add 2 to the <em>Y</em> coordinate and subtract 3 from the <em>Rectangle</em>’s height in the next line to create a margin, so that our header cell’s top and bottom borders are still visible.)</p>
<p>Next we need to find the size our string will be based on its length and the font we’ll be using:</p>
<p><span style="color:#339966;">SizeF sz = e.Graphics.MeasureString(&#8220;My Big Header&#8221;, grid1.Font);</span></p>
<p>Then we figure out where the top will need to be in order to make it vertically centered:</p>
<p><span style="color:#339966;">int headerTop = Convert.ToInt32((headRct.Height / 2) &#8211; (sz.Height / 2)) + 2;</span></p>
<p>Then we set the background color to match the grid’s header color:</p>
<p><span style="color:#339966;">e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), headRct);</span></p>
<p>And finally, we draw the text, starting 2 pixels to the right of the left-most point of our rectangle so it looks nice:</p>
<p><span style="color:#339966;">e.Graphics.DrawString(&#8220;My Big Header&#8221;, grid1.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, hcRct.Left + 2, headerTop);</span></p>
<p>Putting it all together, here’s our <em>Paint()</em> event handler:</p>
<p><span style="color:#339966;">private void grid1_Paint(object sender, PaintEventArgs e)</span><br />
<span style="color:#339966;">{</span><br />
<span style="color:#339966;">    DataGridViewCell hc = grid1.Columns["Column3"].HeaderCell;</span><br />
<span style="color:#339966;">    Rectangle hcRct = grid1.GetCellDisplayRectangle(hc.ColumnIndex, -1, true);</span></p>
<p><span style="color:#339966;">    int multiHeaderWidth = grid1.Columns[hc.ColumnIndex].Width + grid1.Columns[hc.ColumnIndex + 1].Width + grid1.Columns[hc.ColumnIndex + 2].Width + grid1.Columns[hc.ColumnIndex + 3].Width;</span><br />
<span style="color:#339966;">    Rectangle headRct = new Rectangle(hcRct.Left, hc.ContentBounds.Y + 2, multiHeaderWidth, grid1.ColumnHeadersHeight);</span><br />
<span style="color:#339966;">    headRct.Height -= 3;</span></p>
<p><span style="color:#339966;">    SizeF sz = e.Graphics.MeasureString(&#8220;My Big Header&#8221;, grid1.Font);</span><br />
<span style="color:#339966;">    int headerTop = Convert.ToInt32((headRct.Height / 2) &#8211; (sz.Height / 2)) + 2;</span><br />
<span style="color:#339966;">    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), headRct);</span><br />
<span style="color:#339966;">    e.Graphics.DrawString(&#8220;My Big Header&#8221;, grid1.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, hcRct.Left + 2, headerTop);</span><br />
<span style="color:#339966;">}</span></p>
<p>And here’s a screenshot:</p>
<p><img src="http://www.murrayhilltech.com/images/multicolumnheader.png" alt="" /></p>
<p> Hope this helped. Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1108&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/02/11/creating-a-multiple-column-header-within-datagridview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://www.murrayhilltech.com/images/multicolumnheader.png" medium="image" />
	</item>
		<item>
		<title>Using C#, ASP.NET, and ADO.NET To Develop A Multi-Tier App From Start To Finish</title>
		<link>http://nisanthvijay.wordpress.com/2011/01/31/using-c-asp-net-and-ado-net-to-develop-a-multi-tier-app-from-start-to-finish/</link>
		<comments>http://nisanthvijay.wordpress.com/2011/01/31/using-c-asp-net-and-ado-net-to-develop-a-multi-tier-app-from-start-to-finish/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 04:53:41 +0000</pubDate>
		<dc:creator>nisanthvijay</dc:creator>
				<category><![CDATA[Multi-Tier App Start To Finish]]></category>

		<guid isPermaLink="false">http://nisanthvijay.wordpress.com/?p=1113</guid>
		<description><![CDATA[This article assumes a familiarity with Visual Studio 2008 and ASP.NET.  In this article I will show you how to create a simple multi-tier (otherwise known as n-tier) application using ASP.NET.  We are going to be using several ASP.NET controls.  What coding there is will be in the Business Logic Layer, and will be done [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1113&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article assumes a familiarity with Visual Studio 2008 and ASP.NET.  In this article I will show you how to create a simple multi-tier (otherwise known as n-tier) application using ASP.NET.  We are going to be using several ASP.NET controls.  What coding there is will be in the Business Logic Layer, and will be done in C#.  There&#8217;s not too much, and if you only know VB.NET, you should still be able to follow along with no problem.</p>
<p>Multi-tier applications exist for a variety of reasons.  This article won&#8217;t go into too much depth on when and why to use multi-tier architecture, however a quick overview is in order:</p>
<p><strong>What Is Multi-Tier Architecture, And Why Do We Care?</strong></p>
<p>Multi-tier (or n-tier) architecture refers to the practice of separating an application into layers.  Doing so makes it easier for you and other developers to re-use your code.  Typically, a multi-tier application will be broken into three layers:</p>
<ul>
<li><strong>Data Access Layer (DAL):</strong>  This layer contains all the code that interacts with the data store used by the application.  For example, if your data store is a typical RDBMS like Sql Server or Oracle, the data access layer will contain the code that calls the stored procedures in your database to perform reads and writes (or if you don&#8217;t use stored procedures, the data access layer may contain your SQL code).</li>
<li><strong>Business Logic Layer (BLL):</strong>  This layer contains all the code that implements your application&#8217;s business rules.  It makes calls to the DAL, usually on behalf of the Presentation Layer (see below).  The BLL typically contains code that operates on the data received from the DAL prior to passing it back to the Presentation Layer for display to the user.  For example, the BLL may perform calculations based on data retrieved from the DAL to be displayed along with the actual data.</li>
<li><strong>Presentation Layer:</strong>  This layer typically reads and writes to the BLL.  The Presentation Layer is responsible for taking the data it receives from the BLL, formatting it, and displaying it to the user.  It is also responsible for collecting user-entered data and conveying it to the BLL for further processing.  In the .NET world, the Presentation Layer is typically created with either ASP.NET Web Forms, Windows Forms, or more recently WPF (Windows Presentation Foundation).</li>
</ul>
<p>Dividing an application&#8217;s code in this manner allows us to take advantage of distributed deployment. For example, you could deploy your Data Access Layer to a data server, your Business Logic Layer to an application server, and your Presentation Layer to a web server (assuming it was a web-based GUI). Later, should you decide to create a Windows GUI client that consumes the same Business Logic Layer component, you could deploy that client to your users&#8217; desktops and reference the Business component on the application server.  In addition, a distributed, multi-tiered application is much more likely to scale for future growth.</p>
<p><strong>How We&#8217;ll Go About It</strong></p>
<p>We will be creating three Visual Studio projects, all within the same solution for simplicity&#8217;s sake.  The application we create will read and write to database tables which contain information on car manufacturer&#8217;s, makes, and models.  <em>Figure 1</em> shows the structure and relationships of the three tables involved.  You should create these tables for yourself, and when doing so, don&#8217;t forget to specify Primary Keys for each table as indicated in the diagram:</p>
<p><img src="http://www.murrayhilltech.com/images/carsstruct.jpg" alt="" width="350" height="523" /> </p>
<p>I&#8217;ve pre-populated each table as shown in <em>Figure 2</em>, <em>Figure 3</em>, and <em>Figure 4</em>:</p>
<p><img src="http://www.murrayhilltech.com/images/mfrtable.jpg" alt="" width="370" height="165" /><br />
<strong>Figure 2: </strong>Manufacturer table</p>
<p><img src="http://www.murrayhilltech.com/images/maketable.jpg" alt="" width="475" height="247" /><br />
<strong>Figure 3: </strong>Make table</p>
<p><img src="http://www.murrayhilltech.com/images/modeltable.jpg" alt="" width="567" height="590" /><br />
<strong>Figure 4: </strong>Model table</p>
<p>You will need to set these tables up in your database in order to play along with us during the creation of the application.  The data doesn&#8217;t have to match exactly, but the structures of each table does.  Also, when entering data, keep in mind the relationships between the tables as shown in <em>Figure 1 </em>above.</p>
<p>As mentioned earlier, our goal is to create a multi-tier application consisting of a Data Access Layer, a Business Logic Layer, and a Presentation Layer.  There will be absolutely no direct communication between the Presentation Layer and the Data Access Layer.  Furthermore, the Data Access Layer will be totally unaware of the Business Logic Layer, and the Business Logic Layer will be totally unaware of the Presentation Layer.  In this way (as it should always be in multi-tier architecture), each of the layers should be able to support any .NET client. For example, although our Presentation Layer will be web-based, once this application is finished, you will be able to create a new Presentation Layer in Windows Forms (or WPF, for that matter) that can consume the Business Logic Layer we will be building (which in turn will consume the Data Access Layer). </p>
<p>When we are finished building our application, it will allow us to perform maintenance on the three tables above.  It will also contain a reporting function which will enable a user to display a list of all models in the system, including the Manufacturer Name, Make Name, Model Name, and Model Year.</p>
<p><strong>Let&#8217;s Do It</strong></p>
<p>OK, so start off by creating a new solution in Visual Studio, and call it &#8220;Cars&#8221;.  (As I mentioned at the top of the article, I&#8217;m assuming you know your way around Visual Studio, so I&#8217;m not going to take you through creating solutions and projects within Visual Studio.  If you don&#8217;t know how to do that already, please take advantage of the documentation and videos on Microsoft&#8217;s web site to familiarize yourself with these procedures.)</p>
<p><strong>Developing the Data Access Layer</strong></p>
<p>Within the Cars solution, create a new Class Library project and call it &#8220;CarsDAL&#8221;.  This project is where we will develop our Data Access Layer.  Once the project is created, delete the Class1.cs file that gets created by default as we won&#8217;t be needing it.  (I told you there wasn&#8217;t going to be much coding at the beginning, see?)  Then, create a new folder named App_Code in the project.</p>
<p>Right click on the App_Code folder, add a new DataSet, and name it &#8220;CarsDataSet&#8221;. Once the DataSet is added, a Table Adapter Design Window will open.  Right click anywhere within the TableAdapter Design Window, the click on Add, then TableAdapter from the popup menu.  This will launch the TableAdapter Configuration Wizard.  We will now create our first TableAdapter, the Manufacturer TableAdapter, by taking the following steps:</p>
<ul>
<li>On the first page of the TableAdapter Configuration Wizard, choose your data connection, which should point to the &#8220;Cars&#8221; database schema you created in preparation earlier, then click Next.</li>
<li>The next page asks you to choose a Command Type.  For the purposes of this article we will choose the option that says, &#8220;Create New Stored Procedures&#8221;.  Then click Next. </li>
<li>On the next screen, click the Query Builder button, which will load the Query Builder window.  The Add Table dialog box is displayed.  Select Manufacturer, then click the Add button, and then close the Add Table dialog box.  In the Manufacturer table now displayed in the top frame of the Query Builder window, check each of the fields.  Leave the &#8220;*(All Columns)&#8221; checkbox unchecked.  Then click OK in the Query Builder window, and click Next to advance the TableAdapter Configuration Wizard.</li>
<li>In the next screen you are asked to name the four stored procedures that will be created for you for the Manufacturer TableAdapter.  (That&#8217;s right, you don&#8217;t need to create them yourself, Visual Studio does it for you.)  Change the default names so that the four stored procedures are named Manufacturer_s, Manufacturer_i, Manufacturer_u, and Manufacturer_d, for Select, Insert, Update, and Delete respectively.  Click Next.</li>
<li>The next screen is the Choose Methods screen.  We&#8217;re going to uncheck the &#8220;Fill A DataTable&#8221; checkbox, and leave &#8220;Return A DataTable&#8221; and &#8220;GenerateDBDirectMethods&#8221; checkboxes checked.  Also, in the text field under the &#8220;Return A DataTable&#8221; checkbox, change the method name to GetManufacturerData.  Click Next.</li>
<li>The Wizard Results screen will list all of the procedures and methods that were generated for you.  Look these over, then click Finish.</li>
<li>When the TableAdapter Configuration Wizard closes, you should see the Manufacturer TableAdapter represented in the TableAdapter Design Window.  It should contain two sections; the Manufacturer section which lists the fields, and the ManufacturerTableAdapter section which lists the queries available in the TableAdapter.  If you recall, we only created one query for this TableAdapter, called GetManufacturerData(), which returns all of the rows in the Manufacturer table.  It&#8217;s a good idea to create one more query which we will call GetManufacturerDataById(), so that we can load a particular Manufacturer record if necessary.  This query is going to accept the MfrId as a parameter.  We&#8217;ll create it as follows:</li>
<li>Right click on the bottom half of the Manufacturer TableAdapter, anywhere in the ManufacturerTableAdapter section.  Choose Add Query from the popup menu, and you will be presented with the TableAdapter Query ConfigurationWizard.  Choose &#8220;Create New Stored Procedure&#8221;, then click Next.</li>
<li>On the Query Type screen choose the first option, &#8220;SELECT which returns rows&#8221;, then click Next.</li>
<li>In the Generate Stored Procedure screen, you can use the Query Builder, or you can manually type in your query.  It should end up looking like this:SELECT MfrId, MfrName, Created_Date FROM Manufacturer WHERE (MfrId = @MfrId)</li>
<li>Then click Next.  On the Create Stored Procedure screen, name the stored procedure &#8220;Manufacturer_By_Id_s&#8221;, then click Next.</li>
<li>On the Choose Methods screen, uncheck the &#8220;Fill A DataTable&#8221; checkbox and leave the &#8220;Return A DataTable&#8221; checkbox checked.  Change the name of the method to &#8220;GetManufacturerDataById&#8221;, then click Next.</li>
<li>The Wizard Results screen will list all of the procedures and methods that were generated for you.  Look these over, then click Finish.</li>
<li>You should now see the Manufacturer TableAdapter represented in the TableAdapter Design Window with the new method included.</li>
</ul>
<p>Now, repeat each of those steps for the Make table, and then again for the Model table.  Be sure to create &#8220;ById&#8221; queries and methods for each table, passing the appropriate field (MakeId and ModelId) and naming each query correctly depending on the table you&#8217;re dealing with. When you&#8217;re done, there is just one more step and we&#8217;ll be done with the Data Access Layer.</p>
<p>OK, now we need to create just one more TableAdapter in the DAL.  As before, right click on any empty area within the TableAdapter Design Window, and click Add, and then TableAdapter in the popup menu.  This will load the TableAdapter Configuration Wizard one more time:</p>
<ul>
<li>Choose your Cars connection string, then click Next.</li>
<li>Choose Create New Stored Procedures, then click Next.</li>
<li>In the Query Builder window, either click the Query Builder button or manually type your SQL query.  Either way, it should look pretty much like this when you&#8217;re done:SELECT Manufacturer.MfrName, Make.MakeName, Model.ModelName, Model.ModelYear FROM Model INNER JOIN Make ON Model.MakeId = Make.MakeId INNER JOIN Manufacturer ON Make.MfrId = Manufacturer.MfrId</li>
<li>Then click Next.  In the Create Stored Procedures screen, change the name of the Select query to &#8220;ModelReport_s&#8221;.  The rest of the queries won&#8217;t matter since you can&#8217;t insert, update, or delete when joining tables as we did with this query.  Visual Studio is smart enough to recognize this and doesn&#8217;t actually create these queries regardless of what you name them.  (Why it wasn&#8217;t smart enough to just disable them is beyond me.)  Anyway, click Next when that&#8217;s done.</li>
<li>Again you will see the Choose Methods screen.  As before, uncheck the &#8220;Fill A DataTable&#8221; checkbox and leave the &#8220;Return A DataTable&#8221; checkbox checked.  Change the method name to &#8220;GetModelReportData&#8221;.  Click Next.</li>
<li>The Wizard Results screen will list all of the procedures and methods that were generated for you.  Look these over, then click Finish.</li>
</ul>
<p>The Data Access Layer is now complete.  Next, we&#8217;ll take a look at the Business Logic Layer.</p>
<p><strong>Business Logic Layer</strong></p>
<p>Create a new Class Library project in the Cars solution, and call it CarsBLL.  Next, add a reference to the CarsDLL project.  Then rename the Class1.cs file created by default to CarsBLL.cs, add the [System.ComponentModel.DataObject] attribute to the CarsBLL class, and add four fields, one for each adapter created in the DAL. The CarsBLL should look like this at this point:</p>
<p> <span style="color:#008000;">using CarsDAL.App_Code.CarsDataSetTableAdapters;</span><br />
<span style="color:#008000;">using CarsDAL.App_Code;</span></p>
<p><span style="color:#008000;">namespace CarsBLL</span><br />
<span style="color:#008000;">{</span><br />
<span style="color:#008000;">    [System.ComponentModel.DataObject]</span><br />
<span style="color:#008000;">    public class CarsBLL</span><br />
<span style="color:#008000;">    {</span><br />
<span style="color:#008000;">        private ManufacturerTableAdapter _manufacturerAdapter = null;</span><br />
<span style="color:#008000;">        private MakeTableAdapter _makeAdapter = null;</span><br />
<span style="color:#008000;">        private ModelTableAdapter _modelAdapter = null;</span><br />
<span style="color:#008000;">        private ModelReport_sTableAdapter _carsReportAdapter = null;</span><br />
<span style="color:#008000;">    }</span><br />
<span style="color:#008000;">}</span></p>
<p>The [System.ComponentModel.DataObject] attribute, along with the others we will be adding to the methods we create next in this class, will make the BLL and its methods visible to the controls we will be using later in the Presentation Layer.</p>
<p>Next, we&#8217;ll add a property for each adapter, methods to Add, Update, Delete, and Get data for the Manufacturer, Make, and Model tables, and a Get method for the Report adapter.  Note that each of these methods will make calls into the DAL, which as we saw earlier, makes calls to the database.  Once these properties and methods are created, your CarsBLL class should look something like this:</p>
<p><span style="color:#008000;">using System;</span><br />
<span style="color:#008000;">using System.Collections.Generic;</span><br />
<span style="color:#008000;">using System.Linq;</span><br />
<span style="color:#008000;">using System.Text;</span><br />
<span style="color:#008000;">using CarsDAL.App_Code.CarsDataSetTableAdapters;</span><br />
<span style="color:#008000;">using CarsDAL.App_Code;</span></p>
<p><span style="color:#008000;">namespace CarsBLL</span><br />
<span style="color:#008000;">{</span><br />
<span style="color:#008000;">    [System.ComponentModel.DataObject]</span><br />
<span style="color:#008000;">    public class CarsBLL</span><br />
<span style="color:#008000;">    {</span><br />
<span style="color:#008000;">        private ManufacturerTableAdapter _manufacturerAdapter = null;</span><br />
<span style="color:#008000;">        private MakeTableAdapter _makeAdapter = null;</span><br />
<span style="color:#008000;">        private ModelTableAdapter _modelAdapter = null;</span><br />
<span style="color:#008000;">        private ModelReport_sTableAdapter _carsReportAdapter = null;</span></p>
<p><span style="color:#008000;">        protected ManufacturerTableAdapter ManufacturerAdapter</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            get</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                if (_manufacturerAdapter == null)</span><br />
<span style="color:#008000;">                {</span><br />
<span style="color:#008000;">                    _manufacturerAdapter = new ManufacturerTableAdapter();</span><br />
<span style="color:#008000;">                }</span><br />
<span style="color:#008000;">                return _manufacturerAdapter;</span><br />
<span style="color:#008000;">            }</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Select, true)]</span><br />
<span style="color:#008000;">        public DataTable GetManufacturerData()  // Returns data for manufacturer table</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            return ManufacturerAdapter.GetManufacturerData();</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Insert, true)]</span><br />
<span style="color:#008000;">        public bool AddManufacturer(string MfrName)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            // Create a new ManufacturerRow instance</span><br />
<span style="color:#008000;">            CarsDataSet.ManufacturerDataTable mfrs = new CarsDataSet.ManufacturerDataTable();</span><br />
<span style="color:#008000;">            CarsDataSet.ManufacturerRow mfr = mfrs.NewManufacturerRow();</span></p>
<p><span style="color:#008000;">            mfr.MfrName = MfrName;</span></p>
<p><span style="color:#008000;">            // Add the new mfr</span><br />
<span style="color:#008000;">            mfrs.AddManufacturerRow(mfr);</span><br />
<span style="color:#008000;">            int rowsAffected = ManufacturerAdapter.Update(mfrs);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was inserted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Update, true)]</span><br />
<span style="color:#008000;">        public bool UpdateManufacturer(string MfrName, int MfrId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            CarsDataSet.ManufacturerDataTable mfrs = ManufacturerAdapter.GetManufacturerDataById(MfrId);</span><br />
<span style="color:#008000;">            if (mfrs.Count == 0)</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                // no matching record found, return false</span><br />
<span style="color:#008000;">                return false;</span><br />
<span style="color:#008000;">            }</span></p>
<p><span style="color:#008000;">            CarsDataSet.ManufacturerRow mfr = mfrs[0];</span></p>
<p><span style="color:#008000;">            mfr.MfrName = MfrName;</span></p>
<p><span style="color:#008000;">            // Update the mfr record</span><br />
<span style="color:#008000;">            int rowsAffected = ManufacturerAdapter.Update(mfr);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was updated,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Delete, true)]</span><br />
<span style="color:#008000;">        public bool DeleteManufacturer(int MfrId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            int rowsAffected = ManufacturerAdapter.Delete(MfrId);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was deleted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        protected MakeTableAdapter MakeAdapter</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            get</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                if (_makeAdapter == null)</span><br />
<span style="color:#008000;">                {</span><br />
<span style="color:#008000;">                    _makeAdapter = new MakeTableAdapter();</span><br />
<span style="color:#008000;">                }</span><br />
<span style="color:#008000;">                return _makeAdapter;</span><br />
<span style="color:#008000;">            }</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Select, true)]</span><br />
<span style="color:#008000;">        public DataTable GetMakeData()  // Returns data for make table</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            return MakeAdapter.GetMakeData();</span><br />
<span style="color:#008000;">        }</span><br />
<span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Insert, true)]</span><br />
<span style="color:#008000;">        public bool AddMake(string MakeName, int MfrId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            // Create a new MakeRow instance</span><br />
<span style="color:#008000;">            CarsDataSet.MakeDataTable makes = new CarsDataSet.MakeDataTable();</span><br />
<span style="color:#008000;">            CarsDataSet.MakeRow make = makes.NewMakeRow();</span></p>
<p><span style="color:#008000;">            make.MakeName = MakeName;</span><br />
<span style="color:#008000;">            make.MfrId = MfrId;</span><br />
<span style="color:#008000;">            // Add the new mfr</span><br />
<span style="color:#008000;">            makes.AddMakeRow(make);</span><br />
<span style="color:#008000;">            int rowsAffected = MakeAdapter.Update(makes);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was inserted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Update, true)]</span><br />
<span style="color:#008000;">        public bool UpdateMake(string MakeName, int MfrId, int MakeId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            CarsDataSet.MakeDataTable makes = MakeAdapter.GetMakeDataById(MakeId);</span><br />
<span style="color:#008000;">            if (makes.Count == 0)</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                // no matching record found, return false</span><br />
<span style="color:#008000;">                return false;</span><br />
<span style="color:#008000;">            }</span></p>
<p><span style="color:#008000;">            CarsDataSet.MakeRow make = makes[0];</span></p>
<p><span style="color:#008000;">            make.MakeName = MakeName;</span><br />
<span style="color:#008000;">            make.MfrId = MfrId;</span></p>
<p><span style="color:#008000;">            // Update the make record</span><br />
<span style="color:#008000;">            int rowsAffected = MakeAdapter.Update(make);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was updated,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Delete, true)]</span><br />
<span style="color:#008000;">        public bool DeleteMake(int MakeId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            int rowsAffected = MakeAdapter.Delete(MakeId);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was deleted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        protected ModelTableAdapter ModelAdapter</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            get</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                if (_modelAdapter == null)</span><br />
<span style="color:#008000;">                {</span><br />
<span style="color:#008000;">                    _modelAdapter = new ModelTableAdapter();</span><br />
<span style="color:#008000;">                }</span><br />
<span style="color:#008000;">                return _modelAdapter;</span><br />
<span style="color:#008000;">            }</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Select, true)]</span><br />
<span style="color:#008000;">        public DataTable GetModelData()  // Returns data for model table</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            return ModelAdapter.GetModelData();</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Insert, true)]</span><br />
<span style="color:#008000;">        public bool AddModel(string ModelName, int ModelYear, int MakeId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            // Create a new ModelRow instance</span><br />
<span style="color:#008000;">            CarsDataSet.ModelDataTable models = new CarsDataSet.ModelDataTable();</span><br />
<span style="color:#008000;">            CarsDataSet.ModelRow model = models.NewModelRow();</span></p>
<p><span style="color:#008000;">            model.MakeId = MakeId;</span><br />
<span style="color:#008000;">            model.ModelName = ModelName;</span><br />
<span style="color:#008000;">            model.ModelYear = ModelYear;</span><br />
<span style="color:#008000;">            // Add the new model</span><br />
<span style="color:#008000;">            models.AddModelRow(model);</span><br />
<span style="color:#008000;">            int rowsAffected = ModelAdapter.Update(models);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was inserted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">            (System.ComponentModel.DataObjectMethodType.Update, true)]</span><br />
<span style="color:#008000;">        public bool UpdateModel(string ModelName, int ModelYear, int MakeId, int ModelId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            CarsDataSet.ModelDataTable models = ModelAdapter.GetModelDataById(ModelId);</span><br />
<span style="color:#008000;">            if (models.Count == 0)</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                // no matching record found, return false</span><br />
<span style="color:#008000;">                return false;</span><br />
<span style="color:#008000;">            }</span></p>
<p><span style="color:#008000;">            CarsDataSet.ModelRow model = models[0];</span></p>
<p><span style="color:#008000;">            model.MakeId = MakeId;</span><br />
<span style="color:#008000;">            model.ModelName = ModelName;</span><br />
<span style="color:#008000;">            model.ModelYear = ModelYear;</span></p>
<p><span style="color:#008000;">            // Update the model record</span><br />
<span style="color:#008000;">            int rowsAffected = ModelAdapter.Update(model);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was updated,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Delete, true)]</span><br />
<span style="color:#008000;">        public bool DeleteModel(int ModelId)</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            int rowsAffected = ModelAdapter.Delete(ModelId);</span></p>
<p><span style="color:#008000;">            // Return true if precisely one row was deleted,</span><br />
<span style="color:#008000;">            // otherwise false</span><br />
<span style="color:#008000;">            return rowsAffected == 1;</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        protected ModelReport_sTableAdapter CarsReportAdapter</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            get</span><br />
<span style="color:#008000;">            {</span><br />
<span style="color:#008000;">                if (_carsReportAdapter == null)</span><br />
<span style="color:#008000;">                {</span><br />
<span style="color:#008000;">                    _carsReportAdapter = new ModelReport_sTableAdapter();</span><br />
<span style="color:#008000;">                }</span><br />
<span style="color:#008000;">                return _carsReportAdapter;</span><br />
<span style="color:#008000;">            }</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">        [System.ComponentModel.DataObjectMethodAttribute</span><br />
<span style="color:#008000;">        (System.ComponentModel.DataObjectMethodType.Select, true)]</span><br />
<span style="color:#008000;">        public DataTable GetAllModels()  // Returns joined data for reports</span><br />
<span style="color:#008000;">        {</span><br />
<span style="color:#008000;">            return CarsReportAdapter.GetCarData();</span><br />
<span style="color:#008000;">        }</span></p>
<p><span style="color:#008000;">    }</span><br />
<span style="color:#008000;">}</span></p>
<p>Note the attributes added to each method: [System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Select, true)]. Again, this ensures that they are visible to the ObjectDataSource control which will be used in the Presentation Layer.</p>
<p>Now, you may have noticed that the BLL Delete methods all accept one parameter, which represents the primary key for the corresponding table.  We&#8217;re going to have to go back to the DAL and adjust the Delete methods there and in the Delete stored procedures that were generated by Visual Studio.  For some reason, Visual Studio&#8217;s TableAdapter Configuration Wizard generates these methods and procedures so that it&#8217;s necessary to pass a variable for every field into them.  That&#8217;s just ridiculous.  Visual Studio should be able to recognize when a table has a primary key, and it should generate the Delete methods and procedures accordingly.  Well, it doesn&#8217;t, so we&#8217;re going to do that.  (We could leave it the way it is and adjust our BLL to deal with this stupidity, but I have a low tolerance for stupidity.  Besides, it&#8217;s almost as easy to do it correctly, and certainly worth the extra effort.)</p>
<p>So, let&#8217;s go back to our CarsDAL project and take a look at the CarsDataSet.Designer.cs file that was generated by the TableAdapter Configuration Wizard.  Within that file there should be three different methods called InitAdapter(), one for each table in our schema.  Within each of these methods you can see how each command object is created.  You want to look for where the parameters are being added to the command object.  Look for code that looks something like this:</p>
<p> <span style="color:#008000;">this._adapter.DeleteCommand.Parameters.Add(new </span><br />
<span style="color:#008000;"> global::System.Data.SqlClient.SqlParameter(&#8220;@RETURN_VALUE&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.SqlDbType.Variant, 0, </span><br />
<span style="color:#008000;"> global::System.Data.ParameterDirection.ReturnValue, 0, 0, null, </span><br />
<span style="color:#008000;"> global::System.Data.DataRowVersion.Current, false, null, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221;)); </span><br />
<span style="color:#008000;"> </span><br />
<span style="color:#008000;"> this._adapter.DeleteCommand.Parameters.Add(new </span><br />
<span style="color:#008000;"> global::System.Data.SqlClient.SqlParameter(&#8220;@Original_MfrId&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.SqlDbType.Int, 0, </span><br />
<span style="color:#008000;"> global::System.Data.ParameterDirection.Input, 0, 0, &#8220;MfrId&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.DataRowVersion.Original, false, null, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221;)); </span><br />
<span style="color:#008000;"> </span><br />
<span style="color:#008000;"> this._adapter.DeleteCommand.Parameters.Add(new </span><br />
<span style="color:#008000;"> global::System.Data.SqlClient.SqlParameter(&#8220;@Original_MfrName&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.SqlDbType.NVarChar, 0, </span><br />
<span style="color:#008000;"> global::System.Data.ParameterDirection.Input, 0, 0, &#8220;MfrName&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.DataRowVersion.Original, false, null, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221;)); </span><br />
<span style="color:#008000;"> </span><br />
<span style="color:#008000;"> this._adapter.DeleteCommand.Parameters.Add(new </span><br />
<span style="color:#008000;"> global::System.Data.SqlClient.SqlParameter(&#8220;@Original_Created_Date&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.SqlDbType.DateTime, 0, </span><br />
<span style="color:#008000;"> global::System.Data.ParameterDirection.Input, 0, 0, &#8220;Created_Date&#8221;, </span><br />
<span style="color:#008000;"> global::System.Data.DataRowVersion.Original, false, null, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221;));</span></p>
<p>The above code adds four parameters to the DeleteCommand object of the Manufacturer TableAdapter.  We only need the first two; the first parameter represents the return value of the stored procedure, and the second one represents the primary key value of the record to be deleted.  That&#8217;s all we really need, so delete the third and fourth parameters.  Once you&#8217;ve done that, repeat the process for both the Make TableAdapter and the Model TableAdapter.</p>
<p>Now we need to adjust the three stored procedures that perform the Deletes in the respective tables.  You will need to adjust the parameter list within each stored proc so that it only expects the first &#8220;input&#8221; parameter as mentioned above.  In addition, you will need to adjust the WHERE clause in each of these stored procs as well, so that they only include the primary key field.  Here&#8217;s what the Manufacturer_d stored procedure should look like when you&#8217;re done:</p>
<p><span style="color:#0000ff;">CREATE PROCEDURE dbo.Manufacturer_d </span><br />
<span style="color:#0000ff;">        (</span><br />
<span style="color:#0000ff;">            @Original_MfrId int</span><br />
<span style="color:#0000ff;">        ) AS SET NOCOUNT OFF; </span><br />
<span style="color:#0000ff;">        DELETE FROM [Manufacturer] </span><br />
<span style="color:#0000ff;">        WHERE (([MfrId] = @Original_MfrId))</span></p>
<p>You will need to do this for both the Make_d and Model_d stored procedures as well.</p>
<p>We have now completed both the Data Access Layer and the Business Logic Layer.</p>
<p><strong>Presentation Layer</strong></p>
<p>The Presentation Layer is the final piece to our puzzle.  Keep in mind that although I&#8217;ll be using ASP.NET in order to create a web GUI for the purposes of this article, you could just as easily create a Windows Forms or a WPF-based presentation layer for your app, and utilize the exact same Business Logic Layer and Data Access Layer components we created previously.  After all, that is the point of multi-tier architecture.</p>
<p>Within our Cars solution, create a new ASP.NET Web Application project, and name it CarsWeb.  VS will create a <em>Default.aspx</em> page within the project which we will look at soon.  You can leave it alone for now.</p>
<p>Before we start coding, we want to add a reference to the CarsBLL project.  Just right-click on the CarsWeb project, choose Add Reference from the menu, then choose the CarsBLL project from the Project tab. After that&#8217;s done, rebuild the solution.  This will ensure that CarsBLL is visible from within CarsWeb.</p>
<p>Our presentation layer is going to consist of a menu of options which will be contained in <em>Default.aspx</em>.  It will also contain a Maintenance page for each of our tables where a user can view, edit, or delete records.  In addition, there will be a Reports page which will list each model, along with the names of its Manufacturer and Make.  VS already created our <em>Default.aspx</em> page, so just add four new pages, naming them <em>mfrmaint.aspx</em>, <em>makemaint.aspx</em>,<em> modelmaint.aspx</em>,<em> and report.aspx</em>.  You should have five aspx files in total, including <em>Default.aspx</em>.  (Our GUI is not going to be pretty or fancy, but it will be functional.  You can add pretty and fancy at your leisure.)</p>
<p>We&#8217;ll start by adding an ObjectDataSource to the Manufacturer maintenance page:</p>
<ul>
<li>Open up the <em>mfrmaint.aspx</em> page in design mode.</li>
<li>Add an ObjectDataSource control to the page by dragging it in from the Data section of the VS toolbox. It will be named ObjectDataSource1 by default.</li>
<li>Right-click on the ObjectDataSource control and choose Configure Data Source from the context menu.</li>
<li>In the configuration window, choose CarsBLL.CarsBLL from the business objects list, then click Next.</li>
<li>The next screen contains four tabs; SELECT, UPDATE, INSERT, and DELETE. In each of these tabs, ensure that the appropriate method is selected. The chosen methods should be GetManufacturerData(), UpdateManufacturer(), AddManufacturer(), and DeleteManufacturer() respectively.</li>
<li>Click Finish</li>
<li>Switch to Source view, and change the OldValuesParameterFormatString attribute from &#8220;original_{0}&#8221; to just &#8220;{0}&#8221; (due to a bug in the ObjectDataSource control)</li>
</ul>
<p>And now, a GridView control:</p>
<ul>
<li>Open up the <em>mfrmaint.aspx</em> page in design mode again</li>
<li>Add a GridView control to the page by dragging it in from the Data section of the Toolbox</li>
<li>In the Properties window of the GridView control, assign ObjectDataSource1 to the DataSourceID property</li>
<li>In the GridView Tasks sheet, check the following options:  Enable Paging, Enable Sorting, Enable Editing, and Enable Deleting</li>
<li>Set the ReadOnly property to True for the MfrId and Created_Date fields</li>
<li>Set the DataKeyNames attribute of the GridView control to &#8220;MfrId&#8221;, so that the control knows which is the Primary Key field</li>
</ul>
<p>Now, repeat the above steps in both <em>makemaint.aspx</em> and <em>modelmaint.aspx</em> for Make Maintenance and Model Maintenance.  When that&#8217;s all done, meet me at the next paragraph.</p>
<p>Ok, now that the table maintenance pages are done, we&#8217;ll do the Report page.  The report will consist simply of a call to the GetAllModels() method of our BLL.  It&#8217;s just like the table maintenance pages we just completed, only easier.  Open up <em>report.aspx</em> in Design mode and add an ObjectDataSource just like we did on the table maintenance pages.  Right-click on it and choose Configure Data Source from the menu.  In the configuration window, choose CarsBLL.CarsBLL from the business objects list, then click Next.  On the next screen we&#8217;ll only be concerned with the SELECT tab this time.  In the SELECT tab, choose the GetAllModels() method and click Finish.  Next, add a GridView control, and assign ObjectDataSource1 as its DataSourceID property.  Then go to the GridView control&#8217;s GridView Tasks sheet, check Enable Paging and Enable Sorting.</p>
<p>Lastly, open up Default.aspx and create a simple menu with links to each of the other four pages.  Something like this:</p>
<p><span style="color:#ff0000;">&lt;a href=&#8221;report.aspx&#8221;&gt;Run Report&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;</span><br />
<span style="color:#ff0000;">&lt;a href=&#8221;mfrmaint.aspx&#8221;&gt;Manufacturer Maintenance&lt;/a&gt;&lt;br /&gt;</span><br />
<span style="color:#ff0000;">&lt;a href=&#8221;makemaint.aspx&#8221;&gt;Make Maintenance&lt;/a&gt;&lt;br /&gt;</span><br />
<span style="color:#ff0000;">&lt;a href=&#8221;modelmaint.aspx&#8221;&gt;Model Maintenance&lt;/a&gt;&lt;br /&gt;</span></p>
<p>And that&#8217;s it!  Build your solution, and you should have pages that look as follows:</p>
<p><img src="http://www.murrayhilltech.com/images/cars_default.jpg" alt="" width="479" height="364" /><br />
<em>Default.aspx</em></p>
<p><img src="http://www.murrayhilltech.com/images/cars_mfr.jpg" alt="" width="479" height="366" /><br />
<em>mfrmaint.aspx</em></p>
<p><img src="http://www.murrayhilltech.com/images/cars_make.jpg" alt="" width="479" height="367" /><br />
<em>makemaint.aspx</em></p>
<p><img src="http://www.murrayhilltech.com/images/cars_model.jpg" alt="" width="479" height="416" /><br />
<em>modelmaint.aspx</em></p>
<p><img src="http://www.murrayhilltech.com/images/cars_report.jpg" alt="" width="479" height="410" /><br />
<em>report.aspx</em></p>
<p>You can see that I wasn&#8217;t lying when I said the GUI wouldn&#8217;t be pretty, but hopefully I&#8217;ve shed some light on the subject of building a multi-tier application in C#.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nisanthvijay.wordpress.com/1113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nisanthvijay.wordpress.com/1113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nisanthvijay.wordpress.com/1113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nisanthvijay.wordpress.com&amp;blog=12913044&amp;post=1113&amp;subd=nisanthvijay&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nisanthvijay.wordpress.com/2011/01/31/using-c-asp-net-and-ado-net-to-develop-a-multi-tier-app-from-start-to-finish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2295f364b74598e7e75ea99990e2c4c4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nisanthvijay</media:title>
		</media:content>

		<media:content url="http://www.murrayhilltech.com/images/carsstruct.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/mfrtable.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/maketable.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/modeltable.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/cars_default.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/cars_mfr.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/cars_make.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/cars_model.jpg" medium="image" />

		<media:content url="http://www.murrayhilltech.com/images/cars_report.jpg" medium="image" />
	</item>
	</channel>
</rss>
