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

<channel>
	<title>DOT NET RULES</title>
	<atom:link href="http://dotnetstories.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotnetstories.wordpress.com</link>
	<description>Yes, to dance beneath the diamond sky with one hand waving free</description>
	<lastBuildDate>Sun, 08 Nov 2009 11:57:46 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='dotnetstories.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/1a14469d4b7ba9e0f89bffef42cef6b5?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>DOT NET RULES</title>
		<link>http://dotnetstories.wordpress.com</link>
	</image>
			<item>
		<title>Create an Asp.Net web user control with C#</title>
		<link>http://dotnetstories.wordpress.com/2009/10/28/create-an-asp-net-web-user-control-with-c/</link>
		<comments>http://dotnetstories.wordpress.com/2009/10/28/create-an-asp-net-web-user-control-with-c/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 11:05:19 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Web user control]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1110</guid>
		<description><![CDATA[User controls are reusable controls that can be defined once and used whenever we need them, in any of the .aspx pages of our application<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1110&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>User controls are reusable controls that can be defined once and used whenever we need them, in any of the .aspx pages of our application. We do have skins,themes and css to give a standard look to our website. User controls help to achieve that as well because since we define them once and use many times, thus making sure we do not have same controls on pages looking differently. When we make changes to a user control all these changes will be reflected to all instances of the control.</p>
<p>I will try to highlight the following in this post</p>
<ol>
<li>What is a user control and why we need it</li>
<li>How to add Content to a User Control</li>
<li>How to add a User Control to a Web Page</li>
<li>How to define properties in a User Control</li>
<li>How to handle events in a User Control</li>
<li>How to raise events in a User Control</li>
<li>How to access the contents of a User Control</li>
</ol>
<p>We will have to create a simple user control step by step.Imagine you have many pages in your asp.net website. Let&#8217;s say that you are developing a fully functional e-commerce site. You will find that you need to collect user data, e.g address information (shipping address info,billing address info,registration customer address info). In this example we will use a user control to collect customer address data.</p>
<p>We just need Visual Studio 2005/2008 or VS 2010.</p>
<p>1) Launch Visual Studio and create a new asp.net website</p>
<p>2)  Save this website in you local file system and give it a name. Choose C# as your development language for this website</p>
<p>3)  Add new folder to your website and name it <strong>UserControl</strong></p>
<p>4) Right-click on this folder and add a new item. From all the items available select a <strong>Web User</strong> control. Also choose C# as the devlopment language and tick the option <strong>Place code in a seperate file</strong>.Name the control <strong>Address.ascx</strong></p>
<p>5) Switch to the Source view of the <strong>Address.ascx</strong> control.Have a look at the first line.</p>
<p><strong>&lt;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;Address.ascx.cs&#8221; Inherits=&#8221;UserControls_Items_Address&#8221; %&gt;</strong></p>
<p>Notice that even though this directive looks a lot like a page directive it starts with  <strong>@ Control</strong></p>
<p>6)  Open the <strong>Address.ascx.cs</strong> file.Your newly create class does not inherit from theSystem.Web.UI.Page but from</p>
<p>public partial class UserControl_Address : System.Web.UI.UserControl</p>
<p>The classes System.Web.UI.Page and System.Web.UI.UserControl have lots in common since they both inherit from another class,TemplateControl class</p>
<p>For more information click <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.templatecontrol.aspx" target="_blank">here</a></p>
<p>7)  Let&#8217;s work on our new user control. Insert a table in your <strong>&#8220;Address.ascx&#8221; </strong>page. This table should have 4 rows and 2 columns.</p>
<p>8)  Add 4 label web server controls on the first 4 rows of the first column. Set their<strong> ID</strong>property as you like(<strong>AddressLabel1,AddressLabel2,AddressLabel3,PostCodeLabel</strong>). Set their text property like  this</p>
<ul>
<li><strong>Address1</strong></li>
<li><strong>Address2</strong></li>
<li><strong>Address3</strong></li>
<li><strong>PostCode</strong></li>
</ul>
<p>9) Add 4 textbox web server controls on the 4 rows of the second column.Set their <strong>ID</strong>property like this</p>
<p><strong>txtaddr1,txtaddr2,txtaddr3,txtpostcode</strong></p>
<p>10)  In order to add this newly created web user control to the <strong>Default.aspx</strong> page just drag and drop it from the <strong>Solution Explorer</strong> onto the .aspx page</p>
<p>11) Look in the source view of the <strong>Default.aspx</strong> page and notice this line</p>
<p><strong>&lt;%@ Register src=&#8221;UserControl/Address.ascx&#8221; tagname=&#8221;Address&#8221; tagprefix=&#8221;uc1&#8243; %&gt;</strong></p>
<p>This is how the user control is registered with the .aspx page. You will also see this</p>
<p><strong>&lt;uc1:Address ID=&#8221;Address1&#8243; runat=&#8221;server&#8221; /&gt;</strong></p>
<p>Change the<strong> ID</strong> property to <strong>Shipping_Address</strong></p>
<p>12) We can add new server controls to our user control. If we wanted to have a label control as a header we must select the <strong>Address.ascx </strong>and just above the table to insert a new label.Name this label <strong>headingLabel</strong>.</p>
<p>One can set the <strong>Text</strong> property of this new header label control and make it apparent to the end use that we talk about <strong>Shipping Address</strong>. But as I mentioned before we need to use this user control in many places in our website. So we do not want to have a fixed <strong>Text</strong>property but one we can set its value accordingly.</p>
<p>Select the <strong>Default.aspx</strong> page and in the</p>
<p><strong> &lt;uc1:Address ID=&#8221;Shipping_Address</strong><strong>&#8220;  runat=&#8221;server&#8221;/&gt;</strong> section you will see that<strong>headingLabel</strong> is not exposed as a property. It cannot be accessed from our page.</p>
<p>So we must add a new public property on this <strong>UserControl_Address</strong> class.This is the same with every other normal class.</p>
<p>So in the<strong> Address.ascx.cs</strong> file type</p>
<p><em><strong> public string Header<br />
{<br />
set { headingLabel.Text = value; }<br />
}</strong></em></p>
<p>13) Now you can go back to the <strong>Default.aspx</strong> page (Source View) and add the<strong>Header=Shipping Address</strong> <strong>&lt;uc1:Address ID=&#8221;</strong><strong>Shipping_Address</strong><strong>&#8220;  runat=&#8221;server&#8221; Header=&#8221;Shipping Address&#8221;&gt;</strong></p>
<p>14) It is very easy to handle events in a user control.Add a button to the user control. This means that you go to the <strong>Address.ascx</strong> file and drop a button under the table. Set the <strong>ID</strong>property to be <strong>txtNext</strong> and the <strong>Text</strong> property to be <strong>Next</strong>. Add another .aspx page to your website and call it <strong>Checkout.aspx</strong>. Double click on the button and you have the empty event handling routine.</p>
<p>Type the following</p>
<p><strong> protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
Response.Redirect(&#8220;~/Checkout.aspx&#8221;);<br />
}</strong></p>
<p>You see how easy it is to handle events in a user control.</p>
<p>14 ) Let&#8217;s see now, how we can create an event in the user control. First we need to define an event.</p>
<p>When we define an event we must define the signature of the event handler method. We do that by choosing a delegate type.We also must give a name to our event. We will call it<strong>Confirmed </strong>event.</p>
<p>Select the <strong>Address.ascx.cs</strong> and type</p>
<p><strong>public event EndEventHandler Confirmed</strong></p>
<p>So we know now that our user control class will raise an event and we must write some code to actually cause this event to be raised.</p>
<p>So in our <strong>Button_Click</strong> event handler, we type</p>
<p><strong>if (Confirmed!=null) Confirmed(this, new EventArgs());</strong></p>
<p>When the user clicks the button, the <strong>Confirmed</strong> event will be raised.</p>
<p>Select the<strong> Default.aspx</strong> page and in the Source View locate the</p>
<p><strong>&lt;uc1:Address ID=&#8221;</strong><strong>Shipping_Address</strong><strong>&#8220;  runat=&#8221;server&#8221; Header=&#8221;Shipping Address&#8221;/&gt;</strong></p>
<p>and change it to</p>
<p><strong>&lt;uc1:Address ID=&#8221;</strong><strong>Shipping_Address</strong><strong>&#8221; onConfirmed=&#8221;ShippingAdress_Confirmed&#8221;  runat=&#8221;server&#8221; Header=&#8221;Shipping Address&#8221;/&gt;</strong></p>
<p>We just added the event handler in the user control.We do that by entering the name of the event and the name of the event handling routine we will add shortly.</p>
<p>In order to add the <strong>ShippingAdress_Confirmed </strong>event handling routine we go back to the<strong>Default.aspx.cs</strong> file and type</p>
<p><strong>protected void ShippingAdress_Confirmed(object sender, EventArgs e)<br />
{</strong></p>
<p><strong>}</strong></p>
<p>Inside this routine add this line of code:</p>
<p><strong>Response.Write(&#8220;The event has been handled&#8221;); </strong></p>
<p>Run the application and you will see the event raised and handled (the text &#8220;<strong>The event has been handled</strong>&#8221; will be printed in the <strong>Default.aspx</strong> page)</p>
<p>For more information on events have a look <a href="http://msdn.microsoft.com/en-us/library/17sde2xt.aspx" target="_blank">here</a> .</p>
<p>15) Let&#8217;s assume that we need 2 instances of our user contol in the <strong>Default.aspx</strong> page (e.g one for shipping address and one for billing address).Select the <strong>Default.aspx</strong> and add a new user control. Go to the <strong>Source View</strong> and add a <strong>Header</strong> property e.g <strong>Billing Address</strong>. Also set the <strong>ID</strong> property to &#8220;<strong>Billing_Address</strong>&#8220;. You should have something like this</p>
<p><strong>&lt;uc1:Address ID=&#8221;</strong><strong>Billing_Address</strong><strong>&#8221; runat=&#8221;server&#8221; Header=&#8221;Billing Address&#8221; /&gt;.</strong></p>
<p>Run the application and see the 2 user controls.</p>
<p>We need to copy all the fields entered in our Shipping address to the Billing address fields.</p>
<p>So we must access the text properties of the <strong>Shipping_Address</strong> user control and copy them to the <strong>Billing_Address</strong> user control.</p>
<p>You will see that it is impossible to access these textbox values directly  from<strong>ShippingAdress_Confirmed</strong> event handler in the <strong>Default.aspx.cs</strong> class, because these text properties are protected and thus invisible to the event handling routine.</p>
<p>So we need to create some public properties in our user control class.</p>
<p>Select the <strong>Address.asx.cs</strong> file and type</p>
<p><strong> public string Address1<br />
{<br />
get {return txtaddr1.Text; }<br />
set {txtaddr1.Text=value;}<br />
}<br />
public string Address2<br />
{<br />
get { return txtaddr2.Text; }<br />
set { txtaddr2.Text = value; }<br />
}<br />
public string Address3<br />
{<br />
get { return txtaddr3.Text; }<br />
set { txtaddr3.Text = value; }<br />
}<br />
public string PostCode<br />
{<br />
get { return txtpostcode.Text; }<br />
set { txtpostcode.Text = value; }<br />
}</strong></p>
<p>16) Select the <strong>Default.aspx.cs</strong> file and inside the <strong>ShippingAddress_Confirmed</strong> event handling routine, comment out the ( <em>Response.Write(&#8220;The event has been handled&#8221;);</em>) and type<br />
<strong> Billing_Address.Address1 = Shipping_Address.Address1;<br />
Billing_Address.Address2 = Shipping_Address.Address2;<br />
Billing_Address.Address3 = Shipping_Address.Address3;<br />
Billing_Address.PostCode = Shipping_Address.PostCode;</strong></p>
<p>Run your application. Type some address data into the first user control and then click the button.You will see the entered data copied in the second user control.</p>
<p>Hope it helps. If you need the source code just email me.</p>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/10/28/create-an-asp-net-web-user-control-with-c" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4011.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;h=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4021.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;title=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4031.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;title=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4041.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;title=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4051.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;title=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4061.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;Title=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4071.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4081.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4091.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F28%2Fcreate-an-asp-net-web-user-control-with-c&amp;t=Create%20an%20Asp.Net%20web%20user%20control%20with%20C%23" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4101.png" alt="Add to Furl" /></a></p>
Posted in asp.net, C#, Visual Studio 2005, Visual Studio 2008 Tagged: asp.net, Visual Studio 2008, Web user control <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1110&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/10/28/create-an-asp-net-web-user-control-with-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4011.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4021.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4031.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4041.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4051.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4061.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4071.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4081.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4091.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4101.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating an ASP.NET Dynamic Data Web Site with VB.Net</title>
		<link>http://dotnetstories.wordpress.com/2009/10/13/creating-an-asp-net-dynamic-data-web-site-with-vb-net/</link>
		<comments>http://dotnetstories.wordpress.com/2009/10/13/creating-an-asp-net-dynamic-data-web-site-with-vb-net/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 14:09:46 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[VB 2008]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[asp.net 3.5 SP1]]></category>
		<category><![CDATA[dynamic data web site]]></category>
		<category><![CDATA[Field Templates]]></category>
		<category><![CDATA[Page templates]]></category>
		<category><![CDATA[scaffolding]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1078</guid>
		<description><![CDATA[In this post I will show you how to create an ASP.NET Dynamic Data Web Site with VB.Net<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1078&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I wanted to do a post on <strong>ASP.NET Dynamic Data</strong> for a long time. I had a seminar the other day and I was asked if I could blog on this technology, so here I am.</p>
<p>First things first. ASP.NET Dynamic data shipped (August 2008) with .NET 3.5 SP1 and Visual Studio 2008 SP1.Before that it was a part of the &#8220;ASP.NET 3.5 Extensions&#8221; package that was shipped back in 2007.</p>
<p>So why  is this an exciting feature? We can quickly build data centric web-sites that work against a LINQ to SQL (or a LINQ to Entities) object model without having to build any of the pages manually!!!!!<strong>Scaffolding</strong> is an important concept in ASP.NET dynamic data terminology so let&#8217;s give it a formal definition.</p>
<p>Scaffolding is a mechanism that takes the power and functionality of the existing asp.net page framework  and enhances it by dynamically displaying pages based on the data model without a physical page to actually exist.</p>
<p>There are many advantages when using the scaffolding mechanism. Some of them are</p>
<ul>
<li>We have to write very little or no code to create a data-driven Web application. This means quick development time,less bugs and code easier to maintain.</li>
<li>In all pages we have all the CRUD operations available with no effort</li>
<li>Paging,sorting,filtering functionalities are also included-generated</li>
<li>Built-in validation which follows the db schema</li>
</ul>
<p>The  scaffolding mechanism uses templates so we can view the data. When you create you asp.net dynamic data website you will see the <strong>PageTemplates</strong> folder.These are the default templates scaffolding uses to show us the data. Obviously you can change these templates according to your project needs.</p>
<p>I will try to demonstrate all the concepts related with an asp.net dynamic data web site in the following, walktrhough-demo.</p>
<p>In order to follow along you need a VS 2008 SP1 or Visual web developer 2008 SP1 and .Net 3.5 SP1. I have installed SQL Server 2008 Standard edition in my PC. SQL Server 2008/2005 Express editions will work just fine.You can download SQL Server 2008 Express edition from this <a href="http://www.microsoft.com/express/sql/register/" target="_blank">link</a>. I will use VB.Net as the development language.</p>
<p>1) Launch VS 2008 and create a new website</p>
<p>2) From the available templates, select <strong>Dynamic Data Web Site</strong></p>
<p>3) Choose <strong>VB</strong> as the development language, as Location your <strong>File System</strong> and then save your website giving it an appropriate name, e.g <em>Dynamic Data</em></p>
<p>4) Now you will have in your <strong>Solution Explorer</strong> all the files created for us. I urge you to have a look at the <strong>DynamicData</strong> folder and the .aspx pages and templates beneath it.Look closely inside the <strong>PageTemplates</strong> folder.</p>
<p>5) Also have a look at the <strong>FieldTemplates</strong> folder. Scaffolding uses <strong>Field templates</strong> to  create default rendering for displaying and editing data.One can customize the default field templates or create new ones from scratch.Notice that field templates are web user controls.</p>
<p>6) Obviously for this example we will need a database. I will use the Northwind database. This is a well known database and many people are familiar with its schema.You can download the Northwinds database from this <a href="http://msftdbprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=34032" target="_blank">link</a>. When you finish downloading  just drag and drop the .mdf and .ldf files in the <strong>App_Data </strong>special folder.</p>
<p>7) We will use LINQ to SQL(one can use Linq to Entities as well) in order to generate our object model. Select your project from the Solution Explorer and select <strong>Add -&gt; New item -&gt; LINQ to SQL Classes</strong>, change the name to <strong>Northwind.dbml</strong> and click Add.</p>
<p>8) Go to you Server Explorer &#8211; Database Explorer and from the Northwind database drag and drop some tables onto the designer(Categories,Orders,Products,Customers)</p>
<p>9) Now we have our object data model that relates to the underlying db schema thanks to LINQtoSQL. You will have the main class which is <strong>NorthwindDataContext.</strong></p>
<p>10) If we try to run our application we will receive an exception. We must do something else first. We need to open the <strong>Global.asax</strong> file in the Solution Explorer.</p>
<p>In this file you will see commented lines of code and simple comments. Make sure you uncomment this line</p>
<blockquote><p>DefaultModel.RegisterContext(GetType(YourDataContextType), New ContextConfiguration() With {.ScaffoldAllTables = False})</p></blockquote>
<p>and replace the <strong>YourDataContextType</strong> with this <strong>NorthwindDataContext</strong> and also set <strong>.ScaffoldAllTables = True </strong>(which is the not wisest thing to do, in a real world scenario)</p>
<p>11) Run you application. If you have followed all the steps so far, you will see your application up and running. Have a look at the picture below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/10/scaff.jpg"><img class="aligncenter size-full wp-image-1088" title="scaff" src="http://dotnetstories.files.wordpress.com/2009/10/scaff.jpg?w=459&#038;h=258" alt="scaff" width="459" height="258" /></a></p>
<p>12 ) Click on the Categories table. Notice that you can</p>
<ol>
<li>Edit a category</li>
<li>Delete a category</li>
<li>Insert a new category</li>
<li>View Products per category</li>
<li>You can sort by CategoryName</li>
</ol>
<p>13) Click on the Customers table. You will see that we have Paging enabled and choose how many records per page we want displayed.</p>
<p>14) Click on the Orders table and see that we have built-in filtering features with zero effort.</p>
<p>15) Click on the Products table. Click to edit the product. Delete the product name and click Update. You will see a validation error message and the update will fail(as we would want to)</p>
<p>Amazing, truly amazing!!!</p>
<p>16) Have a look at the urls in the browser window. For example if you click the <strong>Categories</strong> table, you will see something like that.</p>
<p><em><strong>http://localhost:6754/Categories/List.aspx</strong></em></p>
<p>You might wonder from where this URL takes its name?</p>
<p>Open your <strong>Global.asax</strong> file again and note the</p>
<blockquote><p>routes.Add(New DynamicDataRoute(&#8220;<strong>{table}/{action}</strong>.aspx&#8221;)</p></blockquote>
<p>You know something&#8230;.. Routing is not just an MVC thing&#8230;</p>
<p>If you close the browser window and return to the Solution Explorer, under the <strong>DynamicData</strong> folder you will see no .aspx pages code generated e.g a Products page or a Customers page. What you must understand is that we are talking about dynamic templating and the display is based on the various templates (which are easily customisable) and the data retrieved from the data model.</p>
<p>That is all.More to follow on Dynamic Data in future posts. Hope it helps.</p>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/10/13/creating-an-asp-net-dynamic-data-web-site-with-vb-net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4013.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;h=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4023.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;title=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4033.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;title=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4043.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;title=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4053.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;title=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4063.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;Title=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4073.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=Creating%20an%20ASP.NET%20Dynamic%20Data%20We...+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4083.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4093.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F10%2F13%2Fcreating-an-asp-net-dynamic-data-web-site-with-vb-net&amp;t=Creating%20an%20ASP.NET%20Dynamic%20Data%20Web%20Site%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4103.png" alt="Add to Furl" /></a></p>
<a name="pd_a_2114114"></a><div class="PDS_Poll" id="PDI_container2114114" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/2114114.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/2114114/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://www.polldaddy.com">survey</a></span>
		</noscript>
Posted in VB 2008, VB 9.0, Visual Studio 2008, Visual Studio 2010 Tagged: asp.net 3.5 SP1, dynamic data web site, Field Templates, Page templates, scaffolding <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1078/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1078/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1078/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1078/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1078/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1078/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1078/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1078/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1078/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1078/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1078&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/10/13/creating-an-asp-net-dynamic-data-web-site-with-vb-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/10/scaff.jpg" medium="image">
			<media:title type="html">scaff</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4013.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4023.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4033.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4043.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4053.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4063.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4073.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4083.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4093.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4103.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET 4.0,SEO and meta tags</title>
		<link>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0seo-and-meta-tags/</link>
		<comments>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0seo-and-meta-tags/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 15:38:29 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1070</guid>
		<description><![CDATA[In this post I will talk about ASP.NET 4.0 and SEO. I will demonstrate how to add meta tags using the Page class or the Page directive<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1070&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am thinking to create a new series of posts regarding ASP.NET and SEO (Search Engine Optimisation). I am going to start with this post , talking about some new features that make our asp.net apps more SEO friendly. At the end of the day, there is no point having a great application and somehow &#8220;scare&#8221; the search engines away. This is going to be a short post so let&#8217;s quickly have a look at meta keywords and ASP.NET 4.0.</p>
<p>Meta keywords and description are important elements of a page and make it search engine friendly. ASP.Net 4.0 added 2 new properties on the Page object to let us define the Meta <strong>Keywords</strong> and <strong>Description.</strong></p>
<p>Create a simple asp.net application using Visual Studio 2010. In the Default.aspx.cs code behind file type</p>
<blockquote><p>Page.MetaKeywords = &#8220;asp.net,vb,c#,css,html,&#8221;;</p>
<p>Page.MetaDescription = &#8220;This is my blog that focuses on ASP.NET.&#8221;;</p></blockquote>
<p>Alternatively we can add those two meta tags in the Page directive</p>
<blockquote><p>&lt;%@ Page Language=&#8221;C#&#8221; MetaKeywords=&#8221;asp.net,vb,c#,css,html&#8221; MetaDescription=&#8221;This is my blog that focuses on ASP.NET.&#8221; AutoEventWireup=&#8221;true&#8221;  CodeFile=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;_Default&#8221; %&gt;</p></blockquote>
<p>Run your application. Go to View-&gt;Source and see the meta tags</p>
<blockquote><p>&lt;/title&gt;&lt;meta name=&#8221;description&#8221; content=&#8221;This is my blog that focuses on ASP.NET.&#8221; /&gt;&lt;meta name=&#8221;keywords&#8221; content=&#8221;asp.net,vb,c#,css,html&#8221; /&gt;&lt;/head&gt;</p>
<p>Hope it helps!!!</p></blockquote>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0seo-and-meta-tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4014.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;h=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4024.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;title=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4034.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;title=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4044.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;title=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4054.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;title=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4064.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;Title=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4074.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=ASP.NET%204.0%2CSEO%20and%20meta%20tags+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4084.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4094.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0seo-and-meta-tags&amp;t=ASP.NET%204.0%2CSEO%20and%20meta%20tags" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4104.png" alt="Add to Furl" /></a></p>
Posted in ASP.NET 4.0, Visual Studio 2010 Tagged: ASP.NET 4.0, SEO <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1070/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1070/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1070/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1070/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1070/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1070&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0seo-and-meta-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4014.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4024.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4034.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4044.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4054.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4064.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4074.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4084.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4094.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4104.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET 4.0 Entity DataSource and GridView</title>
		<link>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0-entity-datasource-and-gridview/</link>
		<comments>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0-entity-datasource-and-gridview/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 14:38:29 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[c# 4.0]]></category>
		<category><![CDATA[.Net 4]]></category>
		<category><![CDATA[entity datasource]]></category>
		<category><![CDATA[Entity framework]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1061</guid>
		<description><![CDATA[Recently I had the time to examine thoroughly my blog stats. From that it was evident people liked a lot the posts regarding the new features in .Net 4.0. So in this post I am going to discuss the new Entity DataSource which is  similar to the LINQ to SQL DataSource, except it allows you to use your Entity Framework data object model instead. I will also demonstrates the new features of the GridView control<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1061&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently I had the time to examine thoroughly my blog stats. From that it was evident people liked a lot the posts regarding the new features in .Net 4.0. So in this post I am going to discuss  the new <strong>Entity DataSource</strong> web server control which is  similar to the LINQ to SQL DataSource, except it allows you to use your Entity Framework data object model instead. I will also demonstrates the new features of the GridView control. I have talked about EF and how to build an application with EF and C# in one of my previous <a href="http://dotnetstories.wordpress.com/2009/06/27/building-an-asp-net-application-with-c-and-entity-framework/" target="_blank">posts</a>. In this post I will talk more about the Entity Datasource object and enhancements made in the GridView control.</p>
<p>I will create a sample website as always so it is easier for you to understand.In order to follow along you must have installed in your PC VS 2010 and the .NET 4.0 framework.Obviously we are going to need a data store for our application. I will use the <em>AdventureWorksLt</em> which you can download from this <a href="http://www.codeplex.com/MSFTDBProdSamples/Wiki/View.aspx?title=AWLTDocs" target="_blank">site</a> .</p>
<p>1) Launch Visual Studio 2010 and create a new web site.</p>
<p>2) Choose Asp.Net application from the available templates and C# as the development language</p>
<p>3) You now have your files in the Solution Explorer window.</p>
<p>4) Choose the <em>default.aspx</em> page and go to your Toolbox and under the Data Controls drag and drop an Entity Datasource control on the page.</p>
<p>5) Now you need an <em>Entity Data model</em> that the Entity Datasource can bind to. In the Solution Explorer add (right-click) a new special folder , <em>App_Code</em></p>
<p>6) Select the <em>App_Code</em> and add a new item(right-click) , ADO.NET Entity Data Model.Leave the default name.</p>
<p>7) In the next window select &#8220;Generate from database&#8221; and click Necxt.</p>
<p>8) In the next window of the Entity model wizard create a new connection to you database (AdventureWorksLT)or select an existing connection that points to the same db.</p>
<p>9) Save the entity connection settings in the web.config file</p>
<p>10) Click Next on the wizard window. From all the available db objects we want to include in our model only tables and more specifically only the <em>Products</em> table.</p>
<p>11) Select the table and click <em>Finish. </em>So now we have a Product Entity with all the mappings to the database.</p>
<p>12) Select the Entity Datasource control and click the arrow on the right-top corner and select Configure Data Source.</p>
<p>13) Select in the <em>Named Connection </em>option of the wizard and select the AdventureWorkLTEntities and click Next</p>
<p>14) In the <em>EntitySetName</em> select Product and from the available Entity values select <em>ProductID,Name,ListPrice,Size,Weightand </em>and click <em>Finish</em>.</p>
<p>15) Drag and drop on the default.aspx page a Gridview control (control in your Toolbox data controls area).Give it some formatting from the AutoFormat options</p>
<p>16) Set the datasource of the Gridview control to the Entity datasource.</p>
<p>17) Enable Sorting,Paging and Selection for the Gridview control</p>
<p>18) Run your application by hitting F5 from your keyboard. If everything is ok you will be able to see a list of products in your page.</p>
<p>The imporevement in the GridView control is about selecting rows.If you selected an item in GridView(the third one for example) and then browsed through the pages the third item in every page will also be selected. That was not always what we wanted. The GridView control did that based on an index it had and used to find the third item on that page.</p>
<p>We can overcome that by enabling the <strong>EnablePersistenSelection</strong> property and setting it to True.</p>
<p>Then we need to select the DataKeynames property and set it to <strong>ProductID</strong>.</p>
<p>19) Now if run our application again and select a product in the first page(6th product), and browse through the pages the product in position 6(index 6) is not selected anymore.Now the selection is made over the underlying primary key and not the index in the view of the GridViewControl</p>
<p>Hope it helps!!!</p>
<p>If you need the source code just email me or just comment on this post.</p>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0-entity-datasource-and-gridview" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4014.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;h=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4024.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;title=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4034.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;title=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4044.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;title=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4054.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;title=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4064.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;Title=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4074.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4084.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4094.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F27%2Fasp-net-4-0-entity-datasource-and-gridview&amp;t=ASP.NET%204.0%20Entity%20DataSource%20and%20GridView" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4104.png" alt="Add to Furl" /></a></p>
Posted in ASP.NET 4.0, c# 4.0, Visual Studio 2010 Tagged: .Net 4, ASP.NET 4.0, entity datasource, Entity framework, Visual Studio 2010 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1061/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1061&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/09/27/asp-net-4-0-entity-datasource-and-gridview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4014.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4024.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4034.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4044.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4054.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4064.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4074.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4084.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4094.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4104.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the ASP.Net Calendar Control</title>
		<link>http://dotnetstories.wordpress.com/2009/09/21/using-the-asp-net-calendar-control/</link>
		<comments>http://dotnetstories.wordpress.com/2009/09/21/using-the-asp-net-calendar-control/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 22:40:23 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[asp.net 2.0]]></category>
		<category><![CDATA[calendar]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1047</guid>
		<description><![CDATA[In this post I will be looking into the ASP.Net calendar control.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1047&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been using my blog to talk primarily about new things and enhancements in the .Net Framework. I have been talking about C# new features,VB new features, LINQ,Entity framework and the new Visual Studio 2010. The other day during a seminar I was asked about a very important ASP.NET 2.0 web server control, the calendar control. So I thought to write a post and look into this very useful control, presenting its basic functionality but also looking into the more advanced functionality it has.</p>
<p>So what is the calendar control.</p>
<p>A simple but powerful definition could be:</p>
<h3>It allows the users to select a date or a range of dates withing an application</h3>
<p>I will be using VS 2008 and C# to create a simple asp.net application.</p>
<p>1) Launch Visual Studio 2005 or 2008.</p>
<p>2) Create a new website and name it with a meaningful name, e.g CalendarSite</p>
<p>3) Drag and drop a Calendar control from the toolbox into the default.aspx page.Leave the default name</p>
<p>4) Let&#8217;s examine some of the most used properties.</p>
<p><strong>SelectedDate</strong>: By setting this property to a value, you have this value-date selected in the calendar control. Set the value to a date and run your application</p>
<p><strong>VisibleDate</strong>:Whenever we want to use a different month or year, when the control initially loads, we can set the VisibleDate property to a date</p>
<p>If you want to select any particular day just click on the hyperlink on the bottom of each day.</p>
<p>5) But what if we wanted to select all of the days of a particular week or all the days of a particulat month.</p>
<p>Then we need to look into another useful property of the Calendar control, the <strong>SelectionMode</strong>. For selecting all the days of the week, you can set its value to <strong>DayWeek</strong>.</p>
<p>For selecting all the days in a month, you can set its value to <strong>DayWeekMonth</strong>.</p>
<p>Run your application and you will see more selectors (arrows) in the calendar control. By clicking on them you will be able to select a whole week or month.</p>
<p>Some other very important properties are:</p>
<ul>
<li>DayNameFormat , which allow us to change the number of letters the header day text contains</li>
<li>FirstDayOfWeek, which allow us to set the first day of the week to Monday if we want to</li>
</ul>
<p>We have so many options to style the control by setting the values of properties like <strong>BorderColor,BordeWidth,BorderStyle,BackColor</strong> to the values we want. We can also set the values of various font properties. We can always use the smart tag(little arrow on the top right hand corner) to use one of the many predefined formatting styles for our calendar control.</p>
<p>Now that I have covered some of the basic stuff, I would like to mention</p>
<ul>
<li>Calendar click events</li>
<li>Control Calendar cell&#8217;s rendering</li>
</ul>
<p>6) Every time the user selects a date in you calendar control, you capture this selection by the <strong>SelectionChanged </strong> event.</p>
<p>Add a literal control to the default.aspx page. Name it <em>SelectedDatesLiteral</em></p>
<p>Just double click on a day in the calendar control. In the event handling routine, type the following</p>
<blockquote><p>foreach (DateTime selectedDate in Calendar1.SelectedDates)<br />
{<br />
SelectedDatesLiteral.Text = string.Format(&#8220;You selected: {0:d}&lt;br/&gt;{1}&#8221;, selectedDate, SelectedDatesLiteral.Text);<br />
}</p></blockquote>
<p>Here, I just loop through the selected dates and append their values to a literal control.Run your application and see for yourself.</p>
<p>7) If we want to add content in a day in the calendar, we must use  the <em>DayRender</em> event. This event is invoked once for every day in the calendar. The table cell and the date are passed to the event handler and can be used to render custom content or look up data in a database etc. We will  pull event data from an xml file.Add an xml file to your project and call it<em> events.xml</em>. Place this file in the App_Data special folder. The contents of this file could be something like this</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;<br />
&lt;Events&gt;<br />
&lt;Event Month=&#8221;1&#8243; Day=&#8221;1&#8243;&gt;Happy New Year.&lt;/Event&gt;<br />
&lt;Event Month=&#8221;2&#8243; Day=&#8221;29&#8243;&gt;Happy leap day.&lt;/Event&gt;<br />
&lt;Event Month=&#8221;12&#8243; Day=&#8221;25&#8243;&gt;&lt;![CDATA[Merry Christmas.]]&gt;&lt;/Event&gt;<br />
&lt;Event Month=&#8221;12&#8243; Day=&#8221;7&#8243;&gt;&lt;![CDATA[Bob's Birthday!]]&gt;&lt;/Event&gt;<br />
&lt;Event Month=&#8221;12&#8243; Day=&#8221;28&#8243;&gt;&lt;![CDATA[16th anniverary]]&gt;&lt;/Event&gt;<br />
&lt;/Events&gt;</p></blockquote>
<p>Add a XMLDataSource control in to your default.aspx page and configure it so it reads the contents of your xml file.</p>
<p>Then in the DayRender Event type the following</p>
<blockquote><p>protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)<br />
{<br />
string xpath = string.Format(&#8220;//Event[@Month={0} and @Day={1}]/text()&#8221;, e.Day.Date.Month, e.Day.Date.Day);<br />
XmlDocument doc = XmlDataSource1.GetXmlDocument();</p>
<p>StringBuilder content = new StringBuilder(e.Day.DayNumberText);<br />
foreach (XmlNode node in doc.SelectNodes(xpath))<br />
{<br />
content.Append(&#8220;&lt;br/&gt;&#8221;);<br />
content.Append(node.Value);<br />
}</p>
<p>e.Cell.Text = content.ToString();<br />
}</p></blockquote>
<p>Make sure you have added these namespaces in the Default.aspx.cs file</p>
<blockquote><p>using System.Xml;<br />
using System.Text;</p></blockquote>
<p>I am using an XPath to filter out only the nodes in our xml document that have content.</p>
<p>Then I am opening the xml document and then I am building a string with values that will be displayed in the calendar cell for the current day.</p>
<p>Then I loop through all the items that were returned back from the XML document and append those values together in order to create a string of all of events that happend in this specific day.</p>
<p>Run your application and see the content that is passed from the xml file to the specific dates, e.g Christmas day.</p>
<p>If you need the full code, just email me.</p>
<p>Hope it helps!!!</p>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/09/21/using-the-asp-net-calendar-control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4015.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;h=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4025.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;title=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4035.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;title=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4045.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;title=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4055.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;title=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4065.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;Title=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4075.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=Using%20the%20ASP.Net%20Calendar%20Control+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4085.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4095.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F21%2Fusing-the-asp-net-calendar-control&amp;t=Using%20the%20ASP.Net%20Calendar%20Control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4105.png" alt="Add to Furl" /></a></p>
Posted in asp.net, C#, Visual Studio 2005, Visual Studio 2008 Tagged: asp.net 2.0, C#, calendar, Visual Studio 2005, Visual Studio 2008 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1047/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1047/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1047/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1047&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/09/21/using-the-asp-net-calendar-control/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4015.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4025.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4035.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4045.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4055.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4065.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4075.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4085.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4095.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4105.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET 4.0 and ClientID Mode</title>
		<link>http://dotnetstories.wordpress.com/2009/09/20/asp-net-4-0-and-clientid-mode/</link>
		<comments>http://dotnetstories.wordpress.com/2009/09/20/asp-net-4-0-and-clientid-mode/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 11:45:22 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[c# 4.0]]></category>
		<category><![CDATA[clientidmode]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1039</guid>
		<description><![CDATA[In ASP.NET 4.0 it is possible to set the name of your controls ClientID attribute. This is possible thanks to the ClientIDMode property<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1039&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I will be continuing my series of posts regarding ASP.NET 4.0 enhancements.It is now possible to set the name of your controls ClientID attribute, thanks to the ClientIDMode property. Developers requested a better way of setting names of the web server controls and with the new version of ASP.NET 4.0, this is now a reality.</p>
<p>We can demonstrate this with a new project.I will be using C# and VS 2010.</p>
<p>1) Launch Visual Studio 2010</p>
<p>2) Create a new website, select ASP.NET Web site from the available templates. Save your website by giving it an appropriate name. e.g Clientid</p>
<p>3) Create a master page and add it to the page.Leave the default name.</p>
<p>4) Create a new web user control.Leave the default name.</p>
<p>5) In the WebUserControl.ascx add two web server controls,a label control and a textbox control</p>
<p>6) Add the web user control to the asp.net page by typing in the directives section(top of the page)</p>
<blockquote><p>&lt;%@ Register src=&#8221;WebUserControl.ascx&#8221; tagname=&#8221;WebUserControl1&#8243;<br />
tagprefix=&#8221;uc1&#8243; %&gt;</p></blockquote>
<p>7) Run your application. When the default.aspx page is render by the browser, go to<strong> View-&gt;Source</strong> and you will see something like this:</p>
<blockquote><p>&lt;div&gt;</p>
<p>&lt;span id=&#8221;WebUserControl11_Label1&#8243;&gt;what is your name?&lt;/span&gt;<br />
&lt;input name=&#8221;WebUserControl11$TextBox1&#8243; type=&#8221;text&#8221; id=&#8221;WebUserControl11_TextBox1&#8243; /&gt;</p>
<p>&lt;/div&gt;</p></blockquote>
<p>This is how the controls take their name. The first part is the name of the parent control and the second part is the name of the control itself. If you have many nested elements you end up with messy control names.If you wanted to access these controls in external Javascript files, you had no other alternative but to use these names.</p>
<p>8) Switch to the WebUserControl.ascx file in VS 2010, and change the ids of the label and textbox control. For example</p>
<blockquote><p>&lt;asp:Label ID=&#8221;namelabel&#8221;<br />
&lt;asp:TextBox ID=&#8221;txtlabel&#8221;</p></blockquote>
<p>9) Then we set the ClientIDMode to static for both controls. Save your work and run the application</p>
<p>10) When the default.aspx page is render by the browser, go to<strong> View-&gt;Source </strong>and you will see something like this:</p>
<blockquote><p>&lt;span id=&#8221;namelabel&#8221;&gt;what is your name?&lt;/span&gt;<br />
&lt;input name=&#8221;WebUserControl11$txtlabel&#8221; type=&#8221;text&#8221; id=&#8221;txtlabel&#8221; /&gt;</p></blockquote>
<p>It is evident that now we have the ID values that we want , and it much easier and handy to use.</p>
<p>The other values for the ClientIDMode are:</p>
<ul>
<li>Legacy: This is equivalent to the ClientID property behavior for earlier versions of ASP.NET. This is also the default value.</li>
</ul>
<ul>
<li> Predictable:This is used in data controls that use repeating templates. It uses ID attributes of the parent control&#8217;s naming containers, but generated IDs do not have names that contain strings like &#8220;ctlxxx&#8221;.</li>
</ul>
<ul>
<li> Inherit: This specifies that a control&#8217;s ID generation is the same as its parent.</li>
</ul>
<p class="getsocial" style="text-align:left;"><a title="Add to Facebook" href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/09/20/asp-net-4-0-and-clientid-mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4012.png" alt="Add to Facebook" /></a><a title="Add to Newsvine" href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;h=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4022.png" alt="Add to Newsvine" /></a><a title="Add to Digg" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;title=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4032.png" alt="Add to Digg" /></a><a title="Add to Del.icio.us" href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;title=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4042.png" alt="Add to Del.icio.us" /></a><a title="Add to Stumbleupon" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;title=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4052.png" alt="Add to Stumbleupon" /></a><a title="Add to Reddit" href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;title=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4062.png" alt="Add to Reddit" /></a><a title="Add to Blinklist" href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;Title=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4072.png" alt="Add to Blinklist" /></a><a title="Add to Twitter" href="http://twitter.com/home/?status=ASP.NET%204.0%20and%20ClientID%20Mode+%40+http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4082.png" alt="Add to Twitter" /></a><a title="Add to Technorati" href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4092.png" alt="Add to Technorati" /></a><a title="Add to Furl" href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F09%2F20%2Fasp-net-4-0-and-clientid-mode&amp;t=ASP.NET%204.0%20and%20ClientID%20Mode" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2009/02/gs4102.png" alt="Add to Furl" /></a></p>
Posted in ASP.NET 4.0, C#, c# 4.0, Visual Studio 2010 Tagged: ASP.NET 4.0, clientidmode <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1039/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1039/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1039/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1039/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1039/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1039/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1039/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1039/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1039/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1039/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1039&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/09/20/asp-net-4-0-and-clientid-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4012.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4022.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4032.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4042.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4052.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4062.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4072.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4082.png" medium="image">
			<media:title type="html">Add to Twitter</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4092.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2009/02/gs4102.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Building an ASP.Net application with C# and Entity Framework</title>
		<link>http://dotnetstories.wordpress.com/2009/06/27/building-an-asp-net-application-with-c-and-entity-framework/</link>
		<comments>http://dotnetstories.wordpress.com/2009/06/27/building-an-asp-net-application-with-c-and-entity-framework/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 19:31:49 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c# 3.0]]></category>
		<category><![CDATA[Entity framework]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1019</guid>
		<description><![CDATA[In this post I will show you a step by step example on how to build an ASP.NET application with C# and Entity Framework. First let's try to define what EF is and why it is going to help us to create easily data-centric applications.Entity Framework is an object-relational mapping (ORM) framework for the .NET Framework.EF addresses the problem of Object-relational impedance mismatch.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1019&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I will show you a step by step example on how to build an ASP.NET application with C# and Entity Framework. First let&#8217;s try to define what EF is and why it is going to help us to create easily data-centric applications.Entity Framework is an object-relational mapping (ORM) framework for the .NET Framework.EF addresses the problem of <a href="http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch" target="_blank">Object-relational impedance mismatch</a>. I will not be talking about that mismatch because it is well documented in many sites on the Internet. Through that framework we can program against a conceptual application model instead of programming directly against a relational schema-model. By doing so we can decrease the amount of code we do write to access a data storage and thus decrease maintenance time.</p>
<p>ADO.NET Entity Framework (EF) is included with .NET Framework 3.5 Service Pack 1 and Visual Studio 2008 Service Pack 1</p>
<p>So you must donwload and have this software installed if you want to follow along.</p>
<p>It is not going to be a very difficult example. I will just bring data from a entity model to a gridview control and then give the user a way to filter that data.</p>
<p>There are many new enhancements regarding EF in VS 2010 and .Net .4.0 framework. I will not be talking about that since these enhancements are brand new and I am currently looking into them. I will just mention model-first development. This feature allows you to create your entity data model from scratch and then generate a database from it!!! We will do the opposite in this example.</p>
<p>Obviously for this example we will need a database. I will use the Pubs database. This is a well known database and many people are familiar with its schema.You can download the Pubs database from this <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46a0-8da2-eebc53a68034&amp;DisplayLang=en" target="_blank">link</a>. If you need some help on how to install the database have a look <a href="http://www.codeproject.com/KB/database/InstallingNorthwindAndPub.aspx" target="_blank">here</a> .</p>
<p>I have installed SQL Server 2008 Standard edition in my PC. SQL Server 2008/2005 Express editions will work just fine.You can download SQL Server 2008 Express edition from this <a href="http://www.microsoft.com/express/sql/register/" target="_blank">link</a>. I have attached the Pubs database in my local instance of the SQL Server.</p>
<p>Let&#8217;s start out project.</p>
<p>1) Launch Visual studio 2008</p>
<p>2) Create a new Project and from the available templates choose &#8220;ASP.Net web application&#8221;</p>
<p>3) Choose C# as your language of development and save your project in your hard drive with a name e.g &#8220;EFWebApplication&#8221; and click &#8220;OK&#8221;.</p>
<p>4) Click on the Solutions Explorer and open the <strong>Default.aspx</strong> page.</p>
<p>5) From the Toolbox drag and drop on the page , a <strong>Gridview</strong> control, a <strong>Textbox</strong> control and <strong>Button</strong> control. Leave the default names.</p>
<p>6) From the Toolbox drag and drop a <strong>EntityDatasource</strong> control on the page.</p>
<p>7) Choose the data source of the gridview control to be the <strong>EntityDatasource1</strong> object.</p>
<p>8) Now we are ready to create our entity model. Right &#8211; click on your project from the <strong>Solutions Explorer</strong> window and <strong>Add a new Item</strong>. From the availble templates choose <strong>ADO.NET Entity data model</strong>. Give it the name <strong>Pubs.edmx </strong>and click the <strong>Add</strong> button.</p>
<p>9) In the <strong>Entity data model wizard </strong>window choose <strong>Generate from database</strong> and click <strong>Next</strong> .</p>
<p>10) Click <strong>New Connection</strong>, choose the <strong>Server name</strong> and from the databases your <strong>Pubs</strong> database is attached and then connect to the <strong>Pubs</strong> database and test your connection and click <strong>OK</strong></p>
<p>11) If you notice you will see that there is something called <strong>Entity connection string</strong> and looks like this</p>
<blockquote><p>metadata=res://*/Pubs.csdl|res://*/Pubs.ssdl|res://*/Pubs.msl;provider=System.Data.SqlClient;provider connection string=&#8221;Data Source=FOFO-PC;Initial Catalog=pubs;Integrated Security=True&#8221;</p></blockquote>
<p>The connection string used by the Entity Framework contains not only the database connection string, but a metadata parameter with pointers to three mapping files separated by a pipe character.These mapping files will be generated when we finish this wizard.</p>
<p>12) Click Next on your wizard window and from the databases objects available choose <strong>Tables</strong> and more specifically the <strong>Titles</strong>, <strong>Authors</strong> and <strong>TitleAuthor</strong> tables. Leave the Model namespace as <strong>pubsModel</strong> and click <strong>Finish</strong>.</p>
<p>13) Our new <strong>Pubs.edmx</strong> file called is created and all the entities are generated which are basically classes derived from the data model . Have a look at the picture below to see the Entity model in the Designer window. You can zoom in and zoom out using the appropriate buttons.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/pubsedmx.jpg"><img class="aligncenter size-full wp-image-1020" title="pubsedmx" src="http://dotnetstories.files.wordpress.com/2009/06/pubsedmx.jpg?w=460&#038;h=287" alt="pubsedmx" width="460" height="287" /></a></p>
<p>14) Have a look at the Mapping details of each entity type (Authors, Titles,  TitleAuthor). You can change if you want the property names for a particular entity type. For example you can change <strong>au_lname</strong> to <strong>lastname</strong> of the Authors entity type. You can also change the names of the entity types and singularise them in a way so they resemble more like a class name. Change <strong>Authors</strong> to <strong>Author</strong> and <strong>Titles</strong> to <strong>Title</strong> from the Designer.</p>
<p>15) Go to your <strong>default.aspx</strong> page and click on the EntityDatasource object and hit the option <strong>Configure Data Source</strong>. In the window that appears choose <strong>Named Connection</strong> and select the <strong>PubsEntities</strong> that will apear in the drop-down and hit the <strong>Next</strong> button.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/pubsef-1.jpg"><img class="aligncenter size-full wp-image-1021" title="pubsef-1" src="http://dotnetstories.files.wordpress.com/2009/06/pubsef-1.jpg?w=460&#038;h=287" alt="pubsef-1" width="460" height="287" /></a></p>
<p>16) In the next step from the EntitySetName select <strong>authors</strong>. Select all fields and and enable automatic inserts,updates,deletes and hit the <strong>Finish</strong> button.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/pubsef-2.jpg"><img class="aligncenter size-full wp-image-1022" title="pubsef-2" src="http://dotnetstories.files.wordpress.com/2009/06/pubsef-2.jpg?w=460&#038;h=287" alt="pubsef-2" width="460" height="287" /></a></p>
<p>17) In your gridview control enable paging,sorting,editing,deleting and selection.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/pubsef-3.jpg"><img class="aligncenter size-full wp-image-1023" title="pubsef-3" src="http://dotnetstories.files.wordpress.com/2009/06/pubsef-3.jpg?w=460&#038;h=287" alt="pubsef-3" width="460" height="287" /></a></p>
<p>18) Build and run your application and see the records in your web page. Try to sort,edit, delete records. Well done!!!!</p>
<p>19) Let&#8217;s give the ability to the user to apply a filter to the data by typing something to the textbox and return only the relevant data.Choose your <strong>EntityDatasource</strong> object and from the <strong>Properties</strong> window select  <strong>Where. </strong>Click on the &#8220;&#8230;&#8221; to launch the Expression editor window.</p>
<p>20) We will create an expression to use it as a filter(e.g filter the records by city name). The expression could be something like this</p>
<p><strong>it.city=@city OR @city IS NULL</strong></p>
<p>This expression above is written in Entity SQL which is T-SQL like syntax.</p>
<p><strong>Click the Add Parameter</strong> button and under name write &#8220;city&#8221; and the value will be a control, so from the <strong>Parameter Source</strong> select <strong>Control</strong> and from the <strong>ControlID</strong> your textbox control (e.g TextBox1)</p>
<p>Go to show advanced properties and in the &#8220;Type&#8221; field choose <strong>String</strong>.  Your settings should be like this:</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/pubsef-4jpg.jpg"><img class="aligncenter size-full wp-image-1024" title="pubsef-4jpg" src="http://dotnetstories.files.wordpress.com/2009/06/pubsef-4jpg.jpg?w=460&#038;h=416" alt="pubsef-4jpg" width="460" height="416" /></a></p>
<p>21) Hit the <strong>OK</strong> button to close the <strong>Expression Editor</strong> window. Hit F5 to run your application. In the textbox type</p>
<p>&#8220;Oakland&#8221; and hit the button control. See the filtered results. That is all!!!! We did that without writing a single line of code.</p>
<p>If you need the source code for this example, just leave a comment and I will email it to you as soon as possible.</p>
<p>Hope it helps!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/06/27/building-an-asp-net-application-with-c-and-entity-framework/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;h=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;Title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;title=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fbuilding-an-asp-net-application-with-c-and-entity-framework%2F&amp;t=Building%20an%20ASP.Net%20application%20with%20C%23%20and%20Entity%20Framework" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" alt="Add to Furl" /></a></p>
Posted in asp.net, c# 3.0, Sql Server, Visual Studio 2008 Tagged: Entity framework <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1019/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1019&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/06/27/building-an-asp-net-application-with-c-and-entity-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/pubsedmx.jpg" medium="image">
			<media:title type="html">pubsedmx</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/pubsef-1.jpg" medium="image">
			<media:title type="html">pubsef-1</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/pubsef-2.jpg" medium="image">
			<media:title type="html">pubsef-2</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/pubsef-3.jpg" medium="image">
			<media:title type="html">pubsef-3</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/pubsef-4jpg.jpg" medium="image">
			<media:title type="html">pubsef-4jpg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Viewstate management and ASP.Net 4.0</title>
		<link>http://dotnetstories.wordpress.com/2009/06/27/viewstate-management-and-asp-net-4-0/</link>
		<comments>http://dotnetstories.wordpress.com/2009/06/27/viewstate-management-and-asp-net-4-0/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 15:59:35 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[VS 2010]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=1009</guid>
		<description><![CDATA[In this post I will talk about Viewstate management in ASP.NET 4.0. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1009&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For people who have been following this blog for some time, they know my favourite subject is ASP.NET.</p>
<p>I think this is the best platform for building web applications nowadays. In ASP.NET 4.0 we have some very interesting new enhancements and new features.</p>
<p>I will try to talk about all of them in separate posts since some people have been complaining that my posts are too long.</p>
<p>In this post I will talk about <strong>Viewstate management in ASP.NET 4.0. </strong></p>
<p>Let&#8217;s have a look first what really <strong>Viewstate</strong> is and what it really does.Unless you move to a new paradigm for building web applications like <strong>ASP.NET MVC </strong>you must have a good knowledge of <strong>Viewstate</strong>.</p>
<p>Viewstate represents the state of the page when it was last processed on the server. We use it to retain values across two successive requests for the same page. It is a hidden field added to the page and is restored on the server before the page request is processed. The Viewstate information travels back and forth with the page itself, but contains no visual elements that need to be rendered. So you must be thinking that this is fantastic news for the web developer. But (there is always a but), the extra information in the Viewstate adds to the size of the page and the information that travels down the wire. I have seen web pages that have an additional <strong>20Kbytes</strong> of Viewstate information.</p>
<p>Every .aspx page derives from the <strong>Page</strong> class or <strong>Page</strong> control and extends it. The default value for the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx" target="_blank"><strong>EnableViewState</strong></a> property for the page is <strong>True</strong>. Through that property we can get or set(enable-disable)  the view state of the control.</p>
<p>If we disable <strong>ViewState</strong> on page level, you cannot enable it on child controls. if you go to the <strong>web.config </strong>and type</p>
<p><strong>&lt;pages enableViewState=&#8221;false&#8221;&gt; </strong></p>
<p>then if you try to enable it on child controls is impossible.</p>
<p>In ASP.NET 4.0 we have the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode(VS.100).aspx" target="_blank"><strong>ViewState</strong></a> property. There are 3 values for this property:<strong>enabled</strong>, <strong>disabled</strong>, <strong>inherit .</strong></p>
<p>We can use this property to enable <strong>Viewstate</strong> for an individual control even if <strong>Viewstate</strong> is disabled for the page. We can disable the <strong>Viewstate</strong> for a control even if it is enabled on a page level.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/06/27/viewstate-management-and-asp-net-4-0/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m04.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;h=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m04.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m04.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m04.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m04.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m04.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;Title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m04.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;title=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m04.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m04.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fviewstate-management-and-asp-net-4-0%2F&amp;t=Viewstate%20management%20and%20ASP.Net%204.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m04.png" alt="Add to Furl" /></a></p>
Posted in ASP.NET 4.0, VS 2010 Tagged: ASP.NET 4.0, ViewState <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/1009/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/1009/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/1009/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/1009/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/1009/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/1009/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/1009/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/1009/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/1009/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/1009/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=1009&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/06/27/viewstate-management-and-asp-net-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m04.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m04.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m04.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m04.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m04.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m04.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m04.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m04.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m04.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m04.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>VB 10.0 new features and Visual Studio 2010 IDE enhancements</title>
		<link>http://dotnetstories.wordpress.com/2009/06/27/vb-10-0-new-features-and-visual-studio-2010/</link>
		<comments>http://dotnetstories.wordpress.com/2009/06/27/vb-10-0-new-features-and-visual-studio-2010/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 21:45:05 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[Visual Basic 10.0]]></category>
		<category><![CDATA[VB 10.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=972</guid>
		<description><![CDATA[In this post I will try with a step by step example to highlight the new features of VB 10.0. I will also highlight some of the new enhancements on VS 2010 IDE.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=972&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have downloaded the .Net 4.0 version of the framework and VS 2010 beta version 1 from the microsoft <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=75cbcbcd-b0e8-40ea-adae-85714e8984e3&amp;displaylang=en" target="_blank">site</a> and I started looking at the new features, IDE e.t.c. Visual studio 2010 has some exciting features.</p>
<p>In this post I will try with a step by step example to highlight the new features of VB 10.0. I will also highlight some of the new enhancements on VS 2010 IDE. There are many new things in .net 4.0 and VS 2010 and certainly I will not cover everything in this post.</p>
<p>The first thing we must do is to create a sample application. I will create a <strong>console</strong> application. So just fire VS 2010 and from the available templates select a Console application.</p>
<h3>Consume first mode</h3>
<p>There is a new enhancement in the IntelliSense functionality. We have two alternatives for IntelliSense statement completion: <strong><span>standard mode</span></strong> and <strong><span>consume-first mode</span></strong>. This basically means that we consume classes,types,methods before we actually define them. Have a look at the picture below. In the <strong>Main() </strong>method I start to use this method without even declaring it first.</p>
<blockquote><p>Sub Main()</p>
<p>addtwonums(3, 5)</p>
<p>End Sub</p></blockquote>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/consume.jpg"><img class="aligncenter size-full wp-image-975" title="consume" src="http://dotnetstories.files.wordpress.com/2009/06/consume.jpg?w=460&#038;h=287" alt="consume" width="460" height="287" /></a></p>
<p>When I type the new method I receive a curly line from the compiler and I can realise that there is not a method with such a name.</p>
<p>If I hit <strong>CTRL + .</strong> a simple method structure is created for me.</p>
<blockquote><p>Private Sub addtwonums(ByVal p1 As Integer, ByVal p2 As Integer)<br />
Throw New NotImplementedException<br />
End Sub</p></blockquote>
<p>Now I can go on and finish my method.</p>
<p>This works equally well with classes I have not implemented yet. I have the declaration below in my Main() method.</p>
<blockquote><p>Dim myperson As New Person</p></blockquote>
<p>With the same mechanism, <strong>CTRL+.</strong> we can have a new <strong>Person.vb</strong> file created in the Solutions window.</p>
<h3>Auto-Implemented Properties</h3>
<p>Auto-implemented properties, which is a <a href="http://dotnetstories.wordpress.com/2008/06/23/c-30-new-language-features-auto-implemented-properties/" target="_blank">feature</a> that was available with C# 3.0, provides us with a way to specify a property of a class without having to write code to <strong>Get</strong> and <strong>Set</strong> the property.If I start setting values to the <strong>myperson</strong> object, like the code below</p>
<blockquote><p>Dim myperson As New Person</p>
<p>myperson.name = &#8220;Michael&#8221;<br />
myperson.surname = &#8220;Owen&#8221;</p>
<p>myperson.Walk()</p></blockquote>
<p>I can create properties (without Get and Set)for the name,surname and a method stub for the <strong>Walk()</strong> method.So in my <strong>Person.vb</strong> file I have:</p>
<blockquote><p>Class Person</p>
<p>Property name As String<br />
Property surname As String<br />
Sub Walk()<br />
Throw New NotImplementedException<br />
End Sub<br />
End Class</p></blockquote>
<p>Also note that you can With auto-implemented properties, a property, including a default value, can be declared in a single line. For example</p>
<blockquote><p>Public Property Name As String = &#8220;John&#8221;</p></blockquote>
<p>It is great seeing that Microsoft has decided to bring VB to the same level as C#. For the future of VB you can listen to this fantastic <a href="http://misfitgeek.com/podcast/misfit-geek-podcast-episode-2-does-vb-have-a-future/" target="_blank">podcast</a> where Joe Stagner talks with Lisa Feigenbaum from the .NET Managed Languages Group. Another great thing is that Αnders Hejlsberg is going to be in charge of the VB language as well. We know Anders is probably the most suitable person for driving VB to the future.</p>
<h3>Collection Initialisers</h3>
<p>Collection initialisers was a <a href="http://dotnetstories.wordpress.com/2008/06/30/object-initialisers-in-c-35/" target="_blank">feature</a> of C# 3.0 and basically it is a new syntax we can create a collection and populate it with an initial set of values. Let&#8217;s create a collection of <strong>List(Person)</strong>. Each value that is supplied in the collection initializer is passed to the appropriate Add method of the collection.Inside my <strong>Main()</strong> method I can create</p>
<blockquote><p>Dim people As New List(Of Person) From {<br />
{New Person With {.name = &#8220;michael&#8221;, .surname = &#8220;owen&#8221;}},<br />
{New Person With {.name = &#8220;kenny&#8221;, .surname = &#8220;daglish&#8221;}},<br />
{New Person With {.name = &#8220;robbie&#8221;, .surname = &#8220;fowler&#8221;}}}</p></blockquote>
<p>Please note that there is no &#8220;_&#8221;, underscore anymore.For more information on this topic see <a href="http://channel9.msdn.com/posts/funkyonex/No-More-Underscrores-in-Visual-Basic-10/" target="_blank">this</a> video and this <a href="http://www.unemployedunderscores.com/" target="_blank">site</a>.</p>
<h3>Multiline Lambdas</h3>
<p>In order to demonstrate this, let&#8217;s add another console application to our solution. Until VB 9.0 we had only inline <a href="http://dotnetstories.wordpress.com/2009/06/25/lambda-expressions-with-vb-net/" target="_blank">lambda</a> expressions. In VB 10.0 we have multiline lambdas. Consider the code below, we just have an array of temperatures and we want to find values greater than 30 degrees.</p>
<blockquote><p>Dim temperatures(4) As String</p>
<p>temperatures(0) = 12<br />
temperatures(1) = 23<br />
temperatures(2) = 34<br />
temperatures(3) = 45</p>
<p><strong>Dim heightemperatures = temperatures.Where(</strong></p>
<p><strong>Function(temperature)<br />
Return (temperature &gt; 30)</strong></p>
<p><strong>End Function).ToList()</strong></p>
<p><strong>heightemperatures.ForEach(Sub(temperature)<br />
Console.WriteLine(temperature)</strong></p>
<p><strong>End Sub)</strong><br />
Console.ReadLine()</p></blockquote>
<p>As you can see in this line bit of the code,</p>
<blockquote><p>Dim heightemperatures = temperatures.Where(Function(temperature)<br />
Return (temperature &gt; 30)</p>
<p>End Function).ToList()</p></blockquote>
<p>I am using a multiline lambda expression where I pass into the temperature.</p>
<p>In this part of the code I just display the temperatures on the console by using  <strong>Lambda statements</strong> (a new feature in vb 10.0) by using the <strong>Sub</strong> keyword.</p>
<blockquote><p>
heightemperatures.ForEach(Sub(temperature)<br />
Console.WriteLine(temperature)</p>
<p>End Sub)
</p></blockquote>
<p>For our array declaration we could use .Instead of typing this</p>
<blockquote><p>Dim temperatures(4) As String</p>
<p>temperatures(0) = 12<br />
temperatures(1) = 23<br />
temperatures(2) = 34<br />
temperatures(3) = 45</p></blockquote>
<p>we could type this equivalent chunk of code</p>
<blockquote><p>Dim temperatures = {12, 23, 34, 45}</p></blockquote>
<p>This is a another new feature called <strong>array literals</strong>.</p>
<h3>Parallel Support</h3>
<p>We can execute parts of our program asynchronously-not in sequence using the Parallel object of the.Net 4.0 framework.</p>
<p>The first thing is to import the relevant namespace at the beginning of our code.</p>
<blockquote><p>Imports System.Threading</p></blockquote>
<p>To give you a simple example , we can write the following bit of code to output two strings in parallel on the console.Place the code inside the Main () routine.</p>
<blockquote><p>Parallel.Invoke(<br />
Sub()<br />
Console.WriteLine(&#8220;My name&#8221;)<br />
Thread.Sleep(4200)<br />
End Sub,<br />
Sub()<br />
Console.WriteLine(&#8220;My surname&#8221;)<br />
Thread.Sleep(1000)<br />
End Sub<br />
)</p></blockquote>
<p>We use the <strong>Invoke</strong> method to execute the tasks in parallel.</p>
<p>Run the code and see that the two strings outputted  simultaneously on the screen.For more information on Parallel computing have a look <a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx" target="_blank">here</a>.</p>
<p><strong>Call Hierarchies</strong></p>
<p>This is a brand new feature of the IDE in VS 2010. If you select a method and right click on it and select V<strong>iew Call Hierarchy</strong> so we can see in a niew window that appears titled &#8220;Call Hierarchy&#8221; which method calls (Calls to) this particular method and what methods this method calls(Calls from). See the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/call-hierarchies.jpg"><img class="aligncenter size-full wp-image-998" title="call hierarchies" src="http://dotnetstories.files.wordpress.com/2009/06/call-hierarchies.jpg?w=460&#038;h=287" alt="call hierarchies" width="460" height="287" /></a></p>
<h3>Quick Symbol Search</h3>
<p>In the code editor if you type <strong>CTRL + ,</strong> the Navigate To window appears. You can enter the name of the type,variable you want and it will find all instances and by clicking on them you will navigate easily to them. Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/quick-search.jpg"><img class="aligncenter size-full wp-image-1000" title="quick search" src="http://dotnetstories.files.wordpress.com/2009/06/quick-search.jpg?w=460&#038;h=287" alt="quick search" width="460" height="287" /></a></p>
<h3>Highlighting References</h3>
<p>We can highlight all instances of a particular of property , method e.t.c by simply clicking on it.</p>
<p>We can navigate between instances with CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW.</p>
<p><strong>Enhancements to ASP.NET Multi-Targeting</strong></p>
<p>In Visual Studio 2008, when we targeted a project for an earlier version of the .NET Framework most features of the development environment adapted to the targeted version. However, IntelliSense displayed language features that are available in the current version, and property windows displayed properties available in the current version. In Visual Studio 2010 only language features and properties available in the targeted version of the .NET Framework are shown.</p>
<p><strong>Code Editor</strong></p>
<p>The new Code Editor makes code easier to read. You can zoom in on text by pressing CTRL and scrolling with the mouse wheel.</p>
<p><strong>Visual Studio Debugger</strong></p>
<p>There are Breakpoint enhancements in VS 2010 such as</p>
<ul>
<li>Searching in the Breakpoints window</li>
<li>Label breakpoints</li>
<li>Import and export breakpoints</li>
<li>String comparison for breakpoint conditions in native debugging</li>
</ul>
<p>See the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/06/breakpoints.jpg"><img class="aligncenter size-full wp-image-1002" title="breakpoints" src="http://dotnetstories.files.wordpress.com/2009/06/breakpoints.jpg?w=460&#038;h=287" alt="breakpoints" width="460" height="287" /></a></p>
<p><strong>Components</strong></p>
<p><span style="text-decoration:underline;">The Chart Control</span></p>
<p>This control sports various chart types, including point, column, bar, area, doughnut and many more.It can be rendered in a 3D mode. For more information click <a href="http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591" target="_blank">here</a> and <a href="http://windowsclient.net/learn/video.aspx?v=98610" target="_blank">here</a> .</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/06/27/vb-10-0-new-features-and-visual-studio-2010/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;h=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;Title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;title=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F27%2Fvb-10-0-new-features-and-visual-studio-2010%2F&amp;t=VB%2010.0%20new%20features%20and%20Visual%20Studio%202010%20IDE%20enhancements" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" alt="Add to Furl" /></a></p>
Posted in Visual Basic 10.0 Tagged: VB 10.0, Visual Studio 2010 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/972/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/972/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/972/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=972&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/06/27/vb-10-0-new-features-and-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/consume.jpg" medium="image">
			<media:title type="html">consume</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/call-hierarchies.jpg" medium="image">
			<media:title type="html">call hierarchies</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/quick-search.jpg" medium="image">
			<media:title type="html">quick search</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/breakpoints.jpg" medium="image">
			<media:title type="html">breakpoints</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions with VB.Net</title>
		<link>http://dotnetstories.wordpress.com/2009/06/25/lambda-expressions-with-vb-net/</link>
		<comments>http://dotnetstories.wordpress.com/2009/06/25/lambda-expressions-with-vb-net/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 18:24:01 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[lambda expressions]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=979</guid>
		<description><![CDATA[Another idea-concept that is tightly linked with LINQ is LAMBDA expressions.

Lambda expressions are shorthand for anonymous delegates . Basically delegates allow you to create a variable that “points” to a method. We can use this variable at any time to invoke the method.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=979&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Another idea-concept that is tightly linked with LINQ is <strong>LAMBDA</strong> expressions.</p>
<p>Lambda expressions are shorthand for anonymous <a href="http://dotnetstories.wordpress.com/2008/07/22/how-to-use-net-delagates-and-event-handling-using-delagates/" target="_blank">delegates</a> . Basically delegates allow you to create a variable that “points” to a method. We can use this variable at any time to invoke the method.</p>
<p>Lambdas are used extensively in LINQ queries, which are by nature pretty functional.</p>
<p>I will start talking a little bit about delegates and giving a short example on delegates before moving into lambda expressions.</p>
<p>You can start a <strong>Console application</strong> project with Visual Studio 2008/2010 (Express editions will also do) . Give your project a name and make sure VB is selected as the language of choice.</p>
<p>The first step when using a delegate is to define its signature. I am going to define a method signature for a function which is basically: its return type, the number of parameters it has, and the data type of each parameter.</p>
<blockquote><p>Public Delegate Function FunctionForString(ByVal s As String) As Boolean</p></blockquote>
<p>Now we can define a method that uses our new delegate as an input parameter.  This particular method will accept a string array, and accept an instance of the delegate (some algorithm to perform on a string), then  for each string in the array, it will apply the algorithm to it the return the array of strings back.</p>
<blockquote><p>Public Function OperateStringArray(ByVal theStrings As String(), ByVal myFunction As FunctionForString) As String()</p>
<p>Dim myList As New List(Of String)<br />
Dim mystring As String</p>
<p>For Each mystring In theStrings</p>
<p>If myFunction(mystring) = True Then<br />
myList.Add(mystring)<br />
End If</p>
<p>Next</p>
<p>Return myList.ToArray()</p>
<p>End Function</p></blockquote>
<p>The code above is very easy to understand. I just loop through the string array that has been passed in and I am going to perform <strong>myFunction</strong>(whatever has been passed in to the input parameter of type delagate) and perform it on each item in the string array, and if that is True, I will add it to a list. It is not confusing as it sounds. When you will run the code step by step it will make sense. Now I need to create a method that matches the delegation declaration.When this method will be passed as an argument to the <strong>OperateStringArray </strong>it becomes an instance of the delegate.</p>
<blockquote><p>Public Function StringsFinishingWithS(ByVal s As String) As Boolean<br />
Return s.EndsWith(&#8220;s&#8221;)<br />
End Function</p></blockquote>
<p>The method above matches the delegate declaration since it takes a string parameter and returns a Boolean result.</p>
<p>Basically it returns True if the string passed in, finishes with an &#8220;s&#8221;.</p>
<p>Now let&#8217;s write the code in our Main routine.</p>
<blockquote><p>Sub Main()</p>
<p>Dim myStrings As String() = {&#8220;Davis&#8221;, &#8220;Jones&#8221;, &#8220;Beckett&#8221;, &#8220;Jordan&#8221;, &#8220;Kennt&#8221;}</p>
<p>Dim stringsA As String() = OperateStringArray(myStrings, AddressOf StringsFinishingWithS)</p>
<p>For Each s In stringsA<br />
Console.WriteLine(s)<br />
Next</p>
<p>Console.WriteLine(&#8220;Press enter to continue &#8230;&#8221;)<br />
Console.ReadLine()</p>
<p>End Sub</p></blockquote>
<p>In this routine, I use our <strong>OperateStringArray</strong>, which knows how to loop through an array of strings (passed in as the the first parameter) and apply an algorithm to it (the method that encapsulates the algorithm is passed in as the second parameter).</p>
<p>Run you application. I suggest you use breakpoints and use F11 to execute step by step and see what is really happening.</p>
<p>The whole code in my Module1.vb module is</p>
<blockquote><p>Module Module1</p>
<p>Public Delegate Function FunctionForString(ByVal s As String) As Boolean</p>
<p>Public Function OperateStringArray(ByVal theStrings As String(), ByVal myFunction As FunctionForString) As String()</p>
<p>Dim myList As New List(Of String)<br />
Dim mystring As String</p>
<p>For Each mystring In theStrings</p>
<p>If myFunction(mystring) = True Then<br />
myList.Add(mystring)<br />
End If</p>
<p>Next</p>
<p>Return myList.ToArray()</p>
<p>End Function</p>
<p>Public Function StringsFinishingWithS(ByVal s As String) As Boolean<br />
Return s.EndsWith(&#8220;s&#8221;)<br />
End Function</p>
<p>Sub Main()</p>
<p>Dim myStrings As String() = {&#8220;Davis&#8221;, &#8220;Jones&#8221;, &#8220;Beckett&#8221;, &#8220;Jordan&#8221;, &#8220;Kennt&#8221;}</p>
<p>Dim stringsA As String() = OperateStringArray(myStrings, AddressOf StringsFinishingWithS)</p>
<p>For Each s In stringsA<br />
Console.WriteLine(s)<br />
Next</p>
<p>Console.WriteLine(&#8220;Press enter to continue &#8230;&#8221;)<br />
Console.ReadLine()</p>
<p>End Sub</p>
<p>End Module</p></blockquote>
<p>Let&#8217;s make some alterations in our code to incorporate the concept of Lambda expressions in it. By doing that we hope to have less and more elegant code. The purpose of Lambda expression is to be a shorthand for an anonymous delegate.</p>
<p>What I will do inside the Main() routine, is to remove the delagate and replace this  bit of code</p>
<blockquote><p>Dim stringsA As String() = OperateStringArray(myStrings, Function(s As String) s.StringsFinishingWithS(&#8220;s&#8221;))</p></blockquote>
<p>with this</p>
<blockquote><p>Dim stringsA As String() = OperateStringArray(myStrings, Function(s As String) s.EndsWith(&#8220;s&#8221;))</p></blockquote>
<p>Our<strong> StringsFinishingWithS</strong> is gone now because we can use a lambda expression instead to perform the simple algorithm. I took the body of the <strong>StringsFinishingWithS</strong> method and in-lined it as the input parameter to <strong>OperateStringArray</strong>.  I define the delegate&#8217;s method signature as:</p>
<p><strong> Function (string S)</strong></p>
<p>to match the <strong>OperateStringArray</strong> function type definition.</p>
<p>We could easily change our code above to work with generics and not just strings.</p>
<p>In order to change the delagate declaration to use generics we do this</p>
<blockquote><p>Public Delegate Function FunctionGeneric(Of T)(ByVal s As T)</p></blockquote>
<p>Our <strong>OperateStringArray</strong> becomes</p>
<blockquote><p>Public Function OperateStringArray(ByVal theStrings As String(), ByVal myFunction As FunctionGeneric(Of String)) As String()</p>
<p>Dim myList As New List(Of String)<br />
Dim mystring As String</p>
<p>For Each mystring In theStrings</p>
<p>If myFunction(mystring) = True Then<br />
myList.Add(mystring)<br />
End If</p>
<p>Next</p>
<p>Return myList.ToArray()</p>
<p>End Function</p></blockquote>
<p>We can use the <strong>Func</strong> instead of  the delegate we defined. <strong>Func</strong> is a generic delegate which can be used by anyone.<br />
Our function <strong>join</strong> given string and string, it returns a &#8220;string&#8221;.Now, I will dynamically assign the parameters and body of the function and name it <strong>join</strong>.</p>
<p>So If I comment everything out and just leave my Main() declaration, I have this chunk of code.</p>
<blockquote><p>Dim join As Func(Of String, String, String) = Function(a, b) a  &amp;  &#8220;  &#8220;  &amp; b</p>
<p>Dim value As String = join(&#8220;nik&#8221;, &#8220;fofo&#8221;)</p>
<p>Console.WriteLine(value.ToString())<br />
Console.ReadLine()</p></blockquote>
<p>If you would like the source code just leave a comment and I will email it to you shortly afterwards.</p>
<p>Hope it helps!!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/06/25/lambda-expressions-with-vb-net/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;h=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;Title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;title=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F25%2Flambda-expressions-with-vb-net%2F&amp;t=Lambda%20Expressions%20with%20VB.Net" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in VB 9.0, Visual Studio 2005, Visual Studio 2008 Tagged: lambda expressions <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/979/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=979&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/06/25/lambda-expressions-with-vb-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Object Oriented Programming Concepts with C#3.0</title>
		<link>http://dotnetstories.wordpress.com/2009/06/21/object-oriented-programming-concepts-with-c3-0/</link>
		<comments>http://dotnetstories.wordpress.com/2009/06/21/object-oriented-programming-concepts-with-c3-0/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 20:35:54 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c# 3.0]]></category>
		<category><![CDATA[C#3.0]]></category>
		<category><![CDATA[Object oriented programming]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=904</guid>
		<description><![CDATA[In this post I will try to explain Object Oriented programming model-paradigm.Some of the topics-concepts, I will try to cover topics like Classes ,Properties , Methods ,Fields ,Members ,Enums,Structures, Abstraction , Encapsulation ,Interfaces ,Static classes, Constructors ,Method overloading,Inheritance ,Overriding methods,Virtual methods,Abstract classes ,Polymorphism ,Delegates ,Events
<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=904&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this blog I try to write about all the latest issues regarding the .Net platform.</p>
<p>But in this post I will try to explain thoroughly the Object Oriented programming model-paradigm.</p>
<p>Speaking from my experience so far, I have identified that the lack of knowledge of basic-advanced <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank">OOP</a> concepts is the main reason that people fail to grasp how to design and implement a .Net application.</p>
<p>Dragging and dropping controls from the Toolbox to an .aspx page and connecting to a database does not mean we know OOP.</p>
<p>Unless you do have a good knowledge of OOP concepts , there is a pretty good chance you will fail in your projects.</p>
<p>In this very long post I will try to explain in details the OOP concepts using C# 3.0 in an ASP.NET application.</p>
<p>Many good people have created very good tutorials which are available on the internet about OOP , but I thought I will have a go myself.Along the way I will show you tips and tricks with <em>do&#8217;s</em> and <em>dont&#8217;s</em>.</p>
<p>Well, some people think, <em>&#8220;I do not need classes and object oriented programming to develop my applications&#8221;</em>.</p>
<p>That is a true. However if you want to create .NET applications you must use objects. Even if you fail to realise it, everything in .Net is an object. When you open a connection to a database that &#8220;connection&#8221; is an object. To put it in one line:</p>
<p><strong>Each class in C# is automatically (implicitly) inherited from the Object class.</strong></p>
<p>I have been posting about C# 3.0 new features in other posts and there will be links where required.</p>
<p>Some of the topics-concepts, I will try to cover are:</p>
<ul>
<li>Classes</li>
<li>Properties</li>
<li>Methods</li>
<li>Fields</li>
<li>Members</li>
<li>Enums</li>
<li>Casting</li>
<li>Structures</li>
<li>Abstraction</li>
<li>Encapsulation</li>
<li>Interfaces</li>
<li>Static classes</li>
<li>Constructors</li>
<li>Method overloading</li>
<li>Inheritance</li>
<li>Overriding methods</li>
<li>Virtual methods</li>
<li>Abstract classes</li>
<li>Polymorphism</li>
<li>Delegates</li>
<li>Events</li>
<li>Assemblies</li>
<li>Namespaces</li>
</ul>
<p>and many more&#8230;</p>
<p>Before jumping into bits of code and create our step by step example, I must explain some basic concepts regarding  OOP.</p>
<ul>
<li><span style="text-decoration:underline;"><strong> What is a class?</strong></span></li>
</ul>
<p>A class is an abstract concept. It is a blueprint. Try to think of a class as e.g  the blueprints of a <span style="text-decoration:underline;"><em>car</em></span><em> </em>in the real world.</p>
<p>The designers of auto mobiles sit in front of their computer (or use paper and pencil) and describe exactly the parts of the auto mobile. They describe how these parts interact, the colour of the car, the height of the car, the size of the engine, the acceleration of the car, if the car has air-conditioning system installed.</p>
<p>Then the mechanics that observe the production line, make sure that the cars built (the actual cars) follow the blueprints outlined in the design stage of building a car.</p>
<p>So a class is a way of describing real world entities. It is the code definition for objects.</p>
<p>The class is the <strong>fundamental building block of code</strong> when creating object-oriented software. A class describes in abstract (in theory) all of the characteristics and behaviour of an object.</p>
<p>The object on the other hand is <strong>the instance of a class</strong>. The real thing, if you excuse my slang&#8230;</p>
<p>So we must start thinking about modelling our applications in terms of objects.</p>
<p>When someone, who has hired us to implement a web site-commerce site for his business, he could outline his view of the web site in plain words&#8230;</p>
<p>&#8221; I would like to have a site where I can keep track of the sales-orders that were placed through the site. I also would like to be able to see the customer details and manage my employees details&#8221;,</p>
<p>Then you must think in terms of <strong>Orders,Customer,Employee classes</strong>-objects for this particular scenario.</p>
<p>This is a first attempt of <strong>Abstraction</strong> for the scenario above.</p>
<p><strong>Abstraction</strong> is the process of representing simplified versions of real-world objects in your classes and objects.</p>
<p>Programming with the OOP paradigm is to decide what a class should represent and breaking down your code into a group of interrelated classes.</p>
<p><span style="text-decoration:underline;"><strong>Members of a class</strong></span></p>
<p>The first thing after finalising the class names is to identify the members of a class.</p>
<p>I will talk about <strong>Properties</strong>, <strong>methods</strong> and <strong>event</strong>s. As we go on I will talk in greater detail about class members.</p>
<ul>
<li><span style="text-decoration:underline;">What is a property ?</span></li>
</ul>
<p>A Property allows you to access an object’s data. Properties can be read-only, so they cannot be modified, while others can be changed. A Property defines the state of an object.It describes its individual data or unique configuration.</p>
<ul>
<li><span style="text-decoration:underline;">What is a method ?</span></li>
</ul>
<p>A method allows you to perform an action with an object. Unlike properties, methods are used for actions that perform a distinct task and may  change the object’s state-property.</p>
<ul>
<li><span style="text-decoration:underline;">What is an event ?</span></li>
</ul>
<p>An event provides notification that something has happened. Objects can fire events to trigger the code we have placed in the event-handling routines-methods. For example, if a user clicks on a button,the button object fires a <strong>Click</strong> event, which our code can react to.</p>
<p>Methods, properties and events can be considered as the <strong>public interface </strong>of a class.</p>
<p>Now we are ready to move on and practice what we have been saying so far.</p>
<p>I assume that people who will read this post, have some experience with C# and Visual studio as a development platform.</p>
<p>I will use Visual Studio 2008 Professional edition. People who have downloaded and installed Visual web developer 2008 can also follow these examples. You can download Visual Web Developer by clicking <a title="Visual web developer" href="http://www.asp.net/downloads/essential/" target="_blank">here</a> .</p>
<p>I will create an ASP.NET application. I will create a base class and then take it from there and try to highlight all the concepts mentioned above. The point of this example is not create super sophisticated classes and methods but to create a simple class with plain properties and methods.</p>
<p>1) Launch VS 2008</p>
<p>2) Go to File-&gt;New-&gt;Project</p>
<p>3) From the templates, choose ASP.NET web application. Make sure you select C# as the language of development</p>
<p>4) Give a name for your project. I name it &#8220;LearnCLass&#8221;. Click <strong>OK</strong> on the Templates window.</p>
<p>5) You will have 2 main files, <em><strong>Default.aspx</strong></em> and <em><strong>Default.aspx.cs</strong></em></p>
<p><span style="text-decoration:underline;"><strong>Building a basic class</strong></span></p>
<p>The class I will construct regards a <strong>Person</strong> class.This class can represent any person, e.g the customer of an e-commerce shop.The <strong>Person</strong> class will store the person&#8217;s data, and it will include the built-in functionality needed to generate a block of HTML that displays the person details on a web page. We will test this class with an ASP.NET page.<br />
Once you’ve defined a class, the first step is to add some basic data. The next example defines five member variables that store information about the person, namely, its name, surname, age, height,weight .</p>
<p>In your default.aspx.cs (code behind file) you have something like this:</p>
<blockquote><p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</p>
<p>namespace LearnCLass<br />
{<br />
public partial class _Default : System.Web.UI.Page<br />
{</p></blockquote>
<p>Then add the class definition</p>
<blockquote><p>public class Person<br />
{<br />
public string name;<br />
public string surname;<br />
public int age;<br />
public decimal height;<br />
public decimal weight;<br />
}</p></blockquote>
<p>Now we have the class definition we need to creating an object. We must use <strong>new</strong> keyword to do that. The<strong> new</strong> keyword instantiates the object, which means it creates a copy of the class in memory. If you define an object but don’t instantiate it, you’ll receive an error from the compiler.The members of a class (methods and properties) are accessed <strong>using dot &#8216;.&#8217; operator</strong> against the reference of the object.</p>
<p>In the Page _Load event handling routine type</p>
<blockquote><p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
Person mynewperson;<br />
mynewperson=new Person();<br />
mynewperson.name = &#8220;nikos&#8221;;<br />
mynewperson.surname = &#8220;kantzelis&#8221;;<br />
mynewperson.age = 31;<br />
mynewperson.weight = 88;<br />
mynewperson.height = 1.78M;<br />
Response.Write(mynewperson.name);<br />
}</p></blockquote>
<p>Run your application by hitting F5 from the keyboard and see the results.</p>
<p>What I am trying to highlight here, is how to create an object from a class.The bit that does it is this:</p>
<h4>Person mynewperson;<br />
mynewperson=new Person();</h4>
<p>One could write it in a single line</p>
<h4>Person mynewperson=new Person();</h4>
<p>But the snippet of code inside the Page_Load method is not very well thought.</p>
<p>One could write <strong>mynewperson.age = -2;</strong></p>
<p>We would not like to have the code above. The reason the code above works is that the properties of the Person class,</p>
<p>are all <strong>public</strong>. That is the <strong>visibility</strong> of the properties is public. Another more technical word for visibility is <em>scope</em>.</p>
<p>This is very important concept and one must understand.</p>
<p>The main accessibility keywords are</p>
<p><strong>public</strong> -Members defined as public can be accessed by any other class<br />
<strong>private -</strong> Members defined as private can be accessed only by code procedures inside the current class<br />
<strong>internal</strong> &#8211; Members defined as internal can be accessed by code procedures in any of the classes in the current assembly (the compiled file)<br />
<strong>protected</strong> Members defined as protected can be accessed by code procedures in the current class or by any class<br />
that inherits from this class</p>
<p>So by having in our example the variables defined as <em>public</em>, this means that any other class or method of another class has direct access to those variables-properties.</p>
<p>We must not design classes like that. In order to have useful classes we must have a way to protect the data within them. This is called, <strong>Encapsulation</strong>. Encapsulation is is the hiding of the internal mechanisms and data of a class behind a defined interface.Other classes , if they need to &#8220;talk&#8221; &#8211; interact with a specific class, they can do so by just knowing its interface. Let me try to explain this better with my car analogy example. When you try to change the gear in your car, imagine the gear system as class or a component, the gear system interacts with another system that commands the car to slow down or accelerate. The gear system does not have to know how it is done, just how to interacts with it.</p>
<p>So let&#8217;s change public to private.</p>
<blockquote><p>private string name;<br />
private string surname;<br />
private int age;<br />
private decimal height;<br />
private decimal weight;</p></blockquote>
<p>Let&#8217;s run the code again. We get the following error. I am sure you get what is going on here. There is no variable name still &#8220;alive-visible&#8221; when we call it in the Page_Load event handling routine.</p>
<h4>Error    1    &#8217;LearnCLass._Default.Person.name&#8217; is inaccessible due to its protection level    C:\Users\fofo\Desktop\webapps\LearnCLass\LearnCLass\Default.aspx.cs    24    25    LearnCLass</h4>
<p>In general objects are automatically released when the appropriate variable goes out of scope. Objects are also released when your application ends. That means that their memory is reclaimed. In the managed applications, the <a href="http://dotnetstories.wordpress.com/2008/04/08/what-is-the-net-framework/" target="_blank">CLR </a>uses a service (garbage collector) that periodically scans for released objects and reclaims the memory they hold.</p>
<p>So , you must be thinking that we have not accomplished anything yet. The truth is that we have not finished yet.</p>
<p>We must write <em><strong>property accessors </strong></em>for the member variables<em><strong>.</strong></em></p>
<p>For the name member variable we have</p>
<blockquote><p>public string Name<br />
{<br />
get<br />
{<br />
return name;<br />
}</p>
<p>set<br />
{<br />
name = value;<br />
}</p>
<p>}</p></blockquote>
<p>With C# 3.0 we had a new feature that is called <strong>Auto-implemented</strong> properties. Have a look <a href="http://dotnetstories.wordpress.com/2008/06/23/c-30-new-language-features-auto-implemented-properties/" target="_blank">here</a> in one of my past posts to find out more about that.Basically with auto implemented properties,  there is no need to implement a private field to store the value.</p>
<p>So we could write the code above like this</p>
<h4>public string Name { get; set; }</h4>
<p>much easier isn&#8217;t it?</p>
<p>We can do that for all property accessors if no no additional logic is required.</p>
<p>So we have</p>
<h4>public string Name { get; set; }<br />
public string Surname { get; set; }</h4>
<p>that means that we can comment out the following lines from our class declaration.</p>
<p><strong>//private string name;<br />
//private string surname;</strong></p>
<p>but for the Age,Height,Weight member variables we require some additional logic for the property accessors.</p>
<p>Just for this example let&#8217;s just assume that a person&#8217;s age must between 1 and 100, his height from 1 to 2.40 and his weight from 30 to 240.</p>
<blockquote><p>public int Age<br />
{<br />
get<br />
{<br />
return age;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 1 || value &gt; 100)<br />
{<br />
throw new Exception(&#8220;Invalid age&#8221;);<br />
}</p>
<p>age = value;<br />
}</p>
<p>}</p>
<p>public decimal Height<br />
{<br />
get<br />
{<br />
return height;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 1.00M || value &gt; 2.40M )<br />
{<br />
throw new Exception(&#8220;Invalid height&#8221;);<br />
}</p>
<p>height = value;<br />
}</p>
<p>}</p>
<p>public decimal Weight<br />
{<br />
get<br />
{<br />
return weight;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 30 || value &gt; 240)<br />
{<br />
throw new Exception(&#8220;Invalid weight&#8221;);<br />
}</p>
<p>weight = value;<br />
}</p>
<p>}</p></blockquote>
<p>When trying to assign an invalidvalue, an exception is thrown by the class code.</p>
<p>Now let&#8217;s create a method for our Person Class.</p>
<p>We can create a very simple method like:</p>
<h4>public void Talk()</h4>
<p>{</p>
<p>// add logic later</p>
<p>}</p>
<p>or we can add a method that returns something (it is not void) and can do something useful.</p>
<p>So we can have a method that calculates the age of the person in years. The method follows:</p>
<blockquote><p>public int CalculateAge(DateTime birthDate)<br />
{DateTime now = DateTime.Today;int years = now.Year &#8211; birthDate.Year;if (now.Month &lt; birthDate.Month || (now.Month == birthDate.Month &amp;&amp; now.Day &lt; birthDate.Day))<br />
&#8211;years;return years;<br />
}</p></blockquote>
<p>It is not something difficult.  We should not focus on how the method does it, right now. Basically I am just using</p>
<p><strong>DateTime</strong> Class in the <strong>System namespace</strong>.</p>
<p>In your Page_Load event you can add to the code already there, the following bit</p>
<blockquote><p>string myDateTimeString;int res;myDateTimeString = &#8220;17 Feb,1977&#8243;;DateTime dt;<br />
dt = Convert.ToDateTime(myDateTimeString);<br />
res=mynewperson.CalculateAge(dt);Response.Write(res.ToString());</p></blockquote>
<p>Run your application and see the results.</p>
<p>The <strong>Person</strong> class so far:</p>
<blockquote><p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</p>
<p>namespace LearnCLass<br />
{<br />
public partial class _Default : System.Web.UI.Page<br />
{</p>
<p>public class Person<br />
{<br />
//private string name;<br />
//private string surname;<br />
private int age;<br />
private decimal height;<br />
private decimal weight;</p>
<p>public int Age<br />
{<br />
get<br />
{<br />
return age;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 1 || value &gt; 100)<br />
{<br />
throw new Exception(&#8220;Invalid age&#8221;);<br />
}</p>
<p>age = value;<br />
}</p>
<p>}</p>
<p>public decimal Height<br />
{<br />
get<br />
{<br />
return height;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 1.00M || value &gt; 2.40M )<br />
{<br />
throw new Exception(&#8220;Invalid height&#8221;);<br />
}</p>
<p>height = value;<br />
}</p>
<p>}</p>
<p>public decimal Weight<br />
{<br />
get<br />
{<br />
return weight;<br />
}</p>
<p>set<br />
{<br />
if (value &lt; 30 || value &gt; 240)<br />
{<br />
throw new Exception(&#8220;Invalid weight&#8221;);<br />
}</p>
<p>weight = value;<br />
}</p>
<p>}</p>
<p>public string Name { get; set; }<br />
public string Surname { get; set; }</p>
<p>public int CalculateAge(DateTime birthDate)<br />
{</p>
<p>DateTime now = DateTime.Today;</p>
<p>int years = now.Year &#8211; birthDate.Year;</p>
<p>if (now.Month &lt; birthDate.Month || (now.Month == birthDate.Month &amp;&amp; now.Day &lt; birthDate.Day))<br />
&#8211;years;</p>
<p>return years;<br />
}</p>
<p>public void Talk()<br />
{<br />
//add logic later<br />
}</p>
<p>}</p>
<p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
Person mynewperson=new Person();<br />
mynewperson.Name = &#8220;nikos&#8221;;<br />
mynewperson.Surname = &#8220;kantzelis&#8221;;<br />
mynewperson.Age = 22;<br />
mynewperson.Weight = 88;<br />
mynewperson.Height = 1.78M;<br />
Response.Write(mynewperson.Name);<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(mynewperson.Surname);<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(mynewperson.Age);<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(mynewperson.Height);<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(mynewperson.Weight);<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
mynewperson.Talk();</p>
<p>string myDateTimeString;</p>
<p>int res;</p>
<p>myDateTimeString = &#8220;17 Feb,1977&#8243;;</p>
<p>DateTime dt;<br />
dt = Convert.ToDateTime(myDateTimeString);<br />
res=mynewperson.CalculateAge(dt);</p>
<p>Response.Write(res.ToString());</p>
<p>mynewperson.Talk();</p>
<p>}<br />
}<br />
}</p></blockquote>
<p>When we create our Person object,</p>
<h4>Person mynewperson=new Person();</h4>
<p>you might think that we have here is a method call.When an instance of a class is created the C# system makes a call to a <strong>constructor</strong> method in that class. A constructor is a function with the same name as that of the class. Every single class must have a constructor method.It is called when we write the <strong>new</strong> keyword. Even If we do not provide a constructor method, the compiler creates a default one,without any parameters.</p>
<p>So in our case is:</p>
<blockquote><p>public Person()</p>
<p>{</p>
<p>}</p></blockquote>
<p>We often need to <strong>overload</strong> our default constructors. Let me explain what <strong>overload</strong> is.</p>
<p>It is possible to have more than one method with the same name and return type but with a different number and type of arguments-parameters. The compiler knows every time which method to call by looking at the number of the arguments. I will explain more about overloading later on.</p>
<p>Sometimes it is better to send some information to the class upfront so it is available as soon as it is constructed. So let&#8217;s overload the default constructor.</p>
<blockquote><p>public Person( string thename, string thesurname, int theage)<br />
{<br />
Name = thename;<br />
Surname=thesurname;<br />
Age = theage;<br />
}</p></blockquote>
<p>We can also have a destructor.<strong>Destructors</strong> are just the opposite of constructors.</p>
<p>It has the same name as the containing class but prefixes it with the ~ (tilde) sign.</p>
<p>It is called automatically when the object is about to be destructed (when <a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" target="_blank">garbage collector</a> is about to destroy your object).</p>
<p>It has no return type just as the constructor does not have one as well.<br />
We declare the destructor in our case like</p>
<blockquote><p>~Person()<br />
{<br />
// place our e.g resource freeing code here<br />
}</p></blockquote>
<p>What really happens is that the C# compiler internally converts the destructor to the <strong>Finalize()</strong> method.</p>
<p>The <strong>Object</strong> class is the parent of all objects in .Net.It contains a method called <strong>Finalize()</strong>.<br />
This method is  be called when your object is garbage collected . One can override this method and put here code for freeing resources that you reserved when using the object.</p>
<blockquote><p>protected override void Finalize()<br />
{<br />
try<br />
{</p>
<p>// put some code here<br />
}<br />
finally<br />
{<br />
base.Finalize();<br />
}<br />
}</p></blockquote>
<p>Do not worry about the <strong>override</strong> keyword. I will explain it later on.</p>
<p>Many people ask me about enums and structures and what they are and how we can use them.</p>
<p><span style="text-decoration:underline;"><strong>What is enum?</strong></span></p>
<p>An enumeration is a group of related constants. Each constant is given a descriptive name.<br />
Every enumerated value corresponds to a preset integer.</p>
<p>Sometimes we want to hold a range of particular values or states. This is a perfect place to use enums.</p>
<p>In our example we could have something like</p>
<blockquote><p>public enum PersonState<br />
{<br />
Married = 1,<br />
Widoewed = 2,<br />
Single = 3,<br />
Divorced = 4<br />
}</p></blockquote>
<p>And then call it from our Page_load event</p>
<blockquote><p>PersonState personstate;</p>
<p>personstate =PersonState.Married;<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(personstate);</p></blockquote>
<p>C# compiler will  represent these states as particular numeric values . But it will do so behind the curtains.</p>
<p>So I can use the enum name values and have more readable code. The concept of enumerated values is extremely important, because the .NET class library uses it extensively.</p>
<p><span style="text-decoration:underline;"><strong>What is a structure ?</strong></span></p>
<p>Structures are lightweight objects. Structures are very similar to classes in C#.</p>
<p>Basically they can hold a collection of different things about a particular item.</p>
<p>They are denoted in C# by the <strong>struct</strong> keyword. In our example we could have a structure like this</p>
<blockquote><p>struct NewPerson<br />
{<br />
public string name;<br />
public string surname;<br />
public int age;<br />
public decimal height;<br />
public decimal weight;</p>
<p>}</p></blockquote>
<p>In the Page_Load event routine we can have</p>
<blockquote><p>NewPerson myperson;</p>
<p>myperson.name = &#8220;John&#8221;;</p>
<p>Response.Write(myperson.name);</p></blockquote>
<p>As you notice there is no need for the <strong>new</strong> keyword.</p>
<p>There is a key difference between objects and structures. Structures are managed in terms of value while objects are managed in terms of reference.</p>
<p>A reference holds the physical address of where the data is stored in memory. So it points to the data. It is not the actual data. On the other hand structure variables hold the actual data.</p>
<p>There are some limitations with structures and even if they have their place when we design a software component, they can never be used to replace a class type.</p>
<p>A structure  for example can neither inherit another class, nor can they be inherited. A structure can implement interfaces.</p>
<p>A common place where we find structures  are Net framework types like System.Int32, System.Double , System.Boolean.If you want to check it out yourselves just place the pointer of your mouse on an<strong> int </strong>declaration and right click. From the right-menu click on the &#8220;Go To Definition &#8220;. Then you will see the definitions. See the picture below.</p>
<div>
<table border="0" cellspacing="0" cellpadding="0" width="633">
<tbody>
<tr>
<td style="padding:0;" align="left" valign="top"></td>
</tr>
</tbody>
</table>
</div>
<p><img src="http://dotnetstories.files.wordpress.com/2009/06/gotodef.jpg" alt="go to def" /></p>
<p><span style="text-decoration:underline;"><strong><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">Inheritance<br />
</span></strong></span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">I know a lot people who use Inheritance in their applications without even realizing.</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">If you look at the <strong>Default.aspx.cs</strong> you can see</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"><strong><em>public partial class _Default : System.Web.UI.Page</em></strong></span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">In plain English , this means that every web page we create is a child of the <strong>Page </strong>class. Inheritance is a form of code reuse. It allows one class to acquire and extend the functionality of another class. There is no need to reinvent the wheel when other people have done this for you. Instead of that you have only to think about the peculiarities of the project at hand.</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">Let&#8217;s assume that we need to create another class,called <strong>Student.</strong></span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">In this class we want to inherit the functionality of the Person class or base class.</span></p>
<h4><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"> class  Student : Person</span></h4>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">Then we want to extend the Parent class. We want to create a new simple method to calculate the total marks achieved by the student.</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">The whole Student class follows. I have explained in detail properties and methods in previous paragraphs.<br />
</span></p>
<blockquote><p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">class  Student : Person<br />
{<br />
private int _marksEnglish;<br />
private int _marksLiterature;<br />
private int _marksIT;<br />
private int _marksMaths;<br />
private int marksTotal;</span></p>
<p>public int marksEnglish<br />
{<br />
get<br />
{<br />
return _marksEnglish;<br />
}<br />
set<br />
{<br />
if (value &lt; 0 || value &gt; 20)<br />
{<br />
throw new Exception(&#8220;Invalid number&#8221;);<br />
}</p>
<p>_marksEnglish = value;<br />
}<br />
}<br />
public int marksLiterature<br />
{<br />
get<br />
{<br />
return _marksLiterature;<br />
}<br />
set<br />
{<br />
if (value &lt; 0 || value &gt; 20)<br />
{<br />
throw new Exception(&#8220;Invalid number&#8221;);<br />
}<br />
_marksLiterature = value;<br />
}<br />
}</p>
<p>public int marksMaths<br />
{<br />
get<br />
{<br />
return _marksMaths;<br />
}<br />
set<br />
{<br />
if (value &lt; 0 || value &gt; 20)<br />
{<br />
throw new Exception(&#8220;Invalid number&#8221;);<br />
}<br />
_marksMaths = value;<br />
}<br />
}</p>
<p>public int marksIT<br />
{<br />
get<br />
{<br />
return _marksIT;<br />
}<br />
set<br />
{<br />
if (value &lt; 0 || value &gt; 20)<br />
{<br />
throw new Exception(&#8220;Invalid number&#8221;);<br />
}<br />
_marksIT = value;<br />
}<br />
}</p>
<p>public int CalculateTotalMarks()<br />
{</p>
<p>marksTotal = marksEnglish + marksLiterature + marksIT + marksMaths;</p>
<p>return marksTotal;<br />
}<br />
}</p></blockquote>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"><br />
</span><br />
<span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;">In our Page_Load event , we can create a new object of type Student.</span></p>
<blockquote><p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"> Student mystudent = new Student();<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
mystudent.Name=&#8221;fofo&#8221;;<br />
Response.Write(mystudent.Name);<br />
mystudent.marksEnglish = 12;<br />
mystudent.marksLiterature = 13;<br />
mystudent.marksIT = 18;</span><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"> </span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"> mystudent.marksMaths = 17;</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"> mystudent.CalculateTotalMarks();</span></p>
<p><span style="font-size:12pt;line-height:115%;font-family:&quot;color:black;"><br />
Response.Write(mystudent.CalculateTotalMarks());</span></p></blockquote>
<p>If you pay attention even though we did not define the Name and Surname properties for the Student class, they are available to the class, since they are inherited. The same applies for the <strong>CalculateAge</strong> method.</p>
<p>Some things worth mentioning regarding inheritance are:</p>
<ul>
<li>C# allows only single class inheritance</li>
<li> Multiple inheritance of classes is not allowed in C#</li>
<li>The Object class defined in the <strong>System namespace</strong> is implicitly the ultimate base class of all the classes in C# and the .NET framework</li>
<li>A class may implement multiple interfaces. We may also declare objects of different classes in a class. This way, the encapsulated class may be instantiated in other classes.</li>
</ul>
<p>Now, we know how to make a new class based on an existing one and extend it.If we want to change the behavior of a method in the base class in the child class we must override it.</p>
<p>Let&#8217;s create a new method in the base class (<strong>Person</strong>) that we want to override it later on the child class. It is just a method that calculates the pay of a person.</p>
<blockquote><p>public double CalculatePay(double hoursWorked, double wageperhour,double tax)<br />
{</p>
<p>return (hoursWorked * wageperhour * tax);<br />
}</p></blockquote>
<p>This method is inherited in the Student class. Let&#8217;s assume that we live in a fantastic world where student&#8217;s money is not taxed if the student worked less than 100 hours.</p>
<p>The first thing to do is to add the word <strong>virtual</strong> to the CalculatePay method.So we have:</p>
<blockquote><p>public <strong>virtual</strong> double CalculatePay(double hoursWorked, double wageperhour,double tax)<br />
{</p>
<p>return (hoursWorked * wageperhour * tax);<br />
}</p></blockquote>
<p>and then to use the word <strong>override</strong> in Student class CalculatePay method</p>
<blockquote><p>public <strong>override</strong> double CalculatePay(double hoursWorked, double wageperhour,double tax)<br />
{<br />
if (hoursWorked &gt; 100)<br />
{</p>
<p>return (hoursWorked * wageperhour * tax);<br />
}<br />
else<br />
{<br />
return (hoursWorked * wageperhour);</p>
<p>}<br />
}</p>
<p>From our Page_Load event we can call this</p>
<p>Response.Write(mystudent.CalculatePay(45, 4, 0.45));</p>
<p>By calling the line above the <strong>CalculatePay </strong>method of the student class will be invoked.This relationship between virtual  methods and the derived class methods that override them enables polymorphism.</p></blockquote>
<p>If we want to stop overriding a class we can use the special word <strong>sealed. </strong>This means that this class cannot be used as the basis for another class.</p>
<p>if you change the</p>
<p><strong>public class Person</strong> to <strong>public sealed class Person </strong></p>
<p>and run your application you will receive an error</p>
<p>&#8220;<strong>cannot derive from sealed type &#8216;LearnCLass._Default.Person</strong>&#8220;</p>
<p>Now it is time to see in greater detail <strong>method overloading</strong>.</p>
<p>In our Person class we can define a new method</p>
<blockquote><p>public string JoinNames(string name, string surname)<br />
{<br />
return name + &#8221; &#8221; + surname;<br />
}</p></blockquote>
<p>Now we could have a different implementation of the method above.</p>
<blockquote><p>public string JoinNames(string prefix, string name, string surname)<br />
{<br />
return prefix + &#8221; &#8221; + name + &#8221; &#8221; + surname;<br />
}</p></blockquote>
<p>In our Page_ Load event if we write the line:</p>
<h4>mynewperson.JoinNames(&#8220;Mr&#8221;,&#8221;nikos&#8221;, &#8220;kantzelis&#8221;)</h4>
<p>The compiler will not complain. It will know which method to invoke depending on the number of the parameters-arguments it &#8220;sees&#8221;.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms173152(VS.100).aspx">Polymorphism</a> (<span lang="en-us">from the Greek meaning               &#8220;having multiple forms&#8221;</span> &#8211; &#8220;Poly&#8221; means many and &#8220;morphy&#8221; means &#8220;shape&#8221;) can be achieved by overloading a method.</p>
<p><span style="text-decoration:underline;"><strong>What is a static class?</strong></span></p>
<p>In .NET we can  use some class members without creating an object first. These are called static members, and they’re accessed by class name. So far in the previous examples we have seen the static property <strong>DateTime.Now</strong> to retrieve a DateTime object that represents the current date and time. We didn&#8217; create a <strong>DateTime</strong> object first.</p>
<p>If we wanted to have a method that determines whether a person can hold a valid driving licence, the method would look like this.</p>
<blockquote><p>public bool AllowedToDrive(int age)<br />
{<br />
if (age &gt;= 18 || age &lt;= 80)<br />
{<br />
return true;<br />
}<br />
else<br />
{<br />
return false;<br />
}</p>
<p>}</p></blockquote>
<p>The method above is a good candidate to become a static method.In order to do that, we just add the word <strong>static</strong></p>
<blockquote><p>public <strong>static </strong>bool AllowedToDrive(int age)<br />
{<br />
if (age &gt;= 18 || age &lt;= 80)<br />
{<br />
return true;<br />
}<br />
else<br />
{<br />
return false;<br />
}</p>
<p>}</p></blockquote>
<p>In our Page_Load event routine,we can write</p>
<p><strong>Person.AllowedToDrive(22)</strong></p>
<p>As you see we do not need an object to invoke our method, just the class name.</p>
<p>So a static member is a member of the class and not a member of an instance of the class.</p>
<p>It takes some experience to determine which methods or classes. One common place where we find static classes and methods is the creation of libraries that provide general functionality, e.g find the square root of a number, find the perimeter of a circle.</p>
<p>The next thing to review is <strong>Interfaces</strong>. I will not cover Interfaces in detail because you can find another <a href="http://dotnetstories.wordpress.com/2008/07/22/interfaces-in-c/" target="_blank">post</a> of mine on Interfaces on this blog.</p>
<p>The Interface is basically a contract between a the Interface and a class. In the Interface we do not have implementation of properties of methods.</p>
<p>The class that implements the Interface or inherits from the Interface must implement the methods defined in the Interface.</p>
<p>A .NET interface is similar to an abstract class in the sense that it’s a kind of a template. More on abstract classes later.</p>
<p>If we define an interface like this</p>
<blockquote><p>interface IPerson<br />
{<br />
double DaysVacation(int yearsOfWork);<br />
}</p></blockquote>
<p>and if we say that the Person class implements the IPerson Interface</p>
<h4>class Person : IPerson</h4>
<p>the Person class must in its body implement the <em>DaysVacation(int yearsOfWork)</em> method.</p>
<blockquote><p>public double DaysVacation(int yearsOfWork)<br />
{</p>
<p>if (yearsOfWork &gt; 25)<br />
{<br />
return 25;<br />
}<br />
else if (yearsOfWork &lt; 25 &amp;&amp; yearsOfWork &gt; 20)<br />
{<br />
return 20;<br />
}<br />
else<br />
{<br />
return 10;<br />
}</p>
<p>}</p></blockquote>
<p><span style="text-decoration:underline;"><strong>What is an abstact class?</strong></span></p>
<p>If we need to provide common fields and members to all subclasses, we create an <strong>Abstract</strong> class. We can create an abstract class, with the use of the <strong>abstract</strong> keyword. Abstract classes cannot be instantiated. In our example if we decide that there are some things that an object of type <strong>Person</strong> must do, then we can make the class <strong>Person</strong> abstract and then get the clild classes to provide the implementation. I will create another class to demonstrate abstract classes, because we need to change los of code in the <strong>Person</strong> class  and I do not want to do that.</p>
<p>In abstract classes we can have abstract members and virtual members. An abstract member is not implemented in the base class and must be implemented in derived classes in order for the class to compile. A virtual member must be implemented in the base class, and if need be (optionally) overriden in the derived class if want the child method to do something different.</p>
<p>Let&#8217;s define our abstract <strong>Vehicle</strong> class.</p>
<blockquote><p>public abstract class Vehicle<br />
{</p>
<p>public string Model { get; set; }<br />
public string Color { get; set; }<br />
public int NumOfDoors { get; set; }<br />
public int NumoOfWheels { get; set; }</p>
<p>public Vehicle(string model, string color)<br />
{<br />
this.Color = color;<br />
this.Model = model;</p>
<p>}<br />
public abstract string Accelarate(int speed);</p>
<p>public virtual double CalculatePetrolCostPerDistance( double distance)</p>
<p>{<br />
double costperkilometer=0.25;<br />
double res;</p>
<p>res = distance * costperkilometer;</p>
<p>return res;<br />
}</p>
<p>}</p></blockquote>
<p>Now we can have another class<strong> Car</strong> that can inherit from the <strong>Vehicle</strong> class. The method <strong>Accelerate</strong> in the Vehicle class must be implemented in the child class.</p>
<blockquote><p>public class Car : Vehicle<br />
{</p>
<p>public Car(string model, string color): base(model,color)<br />
{<br />
//code to be added<br />
}</p>
<p>public override string Accelarate(int speed)<br />
{<br />
return &#8220;I can accelerate. My speed is right now:&#8221;+speed.ToString();<br />
}</p>
<p>public override double CalculatePetrolCostPerDistance(double distance)<br />
{<br />
double costperkilometer = 0.45;<br />
double res;</p>
<p>res = distance * costperkilometer;</p>
<p>return res;<br />
}</p>
<p>}</p></blockquote>
<p>We can create and use an object type Car in our Page_Load event handling routine</p>
<blockquote><p>Car mycar = new Car( &#8220;bmw&#8221;, &#8220;silver&#8221;);<br />
Response.Write(mycar.Accelarate(134));<br />
Response.Write(&#8220;&lt;/br&gt;&#8221;);<br />
Response.Write(&#8220;The cost is: &#8221; + mycar.CalculatePetrolCostPerDistance(125.5).ToString() +&#8221; euros&#8221;);</p></blockquote>
<p>In the child class I have implemented a simple version of the <strong>Accelarate</strong> method by using the <strong>override</strong> keyword and I chose to ovveride <strong>CalculatePetrolCostPerDistance. </strong>But If i did not need any different behaviour for the <strong>CalculatePetrolCostPerDistance </strong>then that would be ok, my class would compile just fine.</p>
<p>Abstract classes are a lot like interfaces, however abstract classes are different in that they contain fully implemented methods alongside the abstract ones.So we do not have to implement the same methods in each of the components that implement a particular interface. An abstract class can contain fields, constructors, or destructors and implement properties while an interface cannot.<br />
An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but <span style="text-decoration:underline;">only one</span> abstract class.</p>
<p><span style="text-decoration:underline;"><strong>What is a delegate?</strong></span></p>
<p>For more information on this topic have a look at this <a href="http://dotnetstories.wordpress.com/2008/07/22/how-to-use-net-delagates-and-event-handling-using-delagates/" target="_blank">post</a> of mine.</p>
<p><span style="text-decoration:underline;"><strong>What is Generics</strong></span> ?</p>
<p>Same applies here. I have another single post on <a href="http://dotnetstories.wordpress.com/2008/07/09/generics-in-c-20-and-limitations-of-arraylists/" target="_blank">Generics</a> and I do not see any point repeating myself.</p>
<p><span style="text-decoration:underline;"><strong>What is a namespace?</strong></span></p>
<p>In my solution in the <strong>Default.aspx.cs</strong> , I have the <strong>namespace LearnCLass</strong> namespace. All my classes and code is included in this namespace.</p>
<p>Namespaces are a logical way to group classes. Let me give you an example of what it means. It is a way that we can identify a class beyond doubt.</p>
<p>Imagine that you want to phone an old friend that you have lost track, so you can invite him to your wedding. So you phone the phone directory service.</p>
<p>Your friend&#8217;s name is <em>George Patouxas</em>. The operator lets you know that there are 100 people with this name coming up. Then you tell the operator that his mother&#8217;s name and father&#8217;s name are <em>Maria</em> and <em>John</em> respectively. BINGO!! The operator tells you there is only match. So in our example the <strong>LearnCLass.Person </strong>class resides in this specific namespace and if someone wants to use it, he can use the<strong> using LearnCLass.Person </strong>declaration<strong>.<br />
</strong></p>
<p>That is exactly why namespaces are for in .NET.  We try to group related classes in namespaces and all of them that reside in this particular namespace will be uniquely identified.</p>
<p>If I have a class called <strong>Calculate</strong> in my <strong>LearnClass</strong> namespace, then there will be no conflict if need be to use another component from a third party that has also a <strong>Calculate</strong> Class.</p>
<p>That <strong>Calculate</strong> class will reside in the <strong>AnotherNameSpace</strong> so there will be no conflict.</p>
<p>Please note that in the beginning of the Default.aspx.cs we import namespaces that we need to <strong>using System.Web.UI</strong>;</p>
<p><span style="text-decoration:underline;"><strong>Assemblies<br />
</strong></span></p>
<p>All .NET classes (built-in or custom made) are contained in assemblies. Assemblies are the physical files that contain compiled code. Assembly files have the extension .exe if they are stand-alone applications or .dll if they’re reusable components. Assemblies are a physical package for distributing code. Often, assemblies and namespaces have the same names. For example, you’ll find the namespace <strong>System.Web</strong> in the assembly file <strong>System.Web.dll</strong>.</p>
<p>But in many cases there is no direct mapping between assemblies and namespaces.</p>
<p><span style="text-decoration:underline;"><strong>What is Casting?</strong></span></p>
<p>When we talk about casting, we can think of this concept in terms of <em>narrowing</em> and <em>widening</em>. If you move a value from one type to another that <em>narrows</em> the value, it will ask you to explicitly do it yourself. When you move a value from one type to another by widening it, it does not complain.</p>
<p>By widening I mean that if I have the declaration:</p>
<blockquote>
<h4>int mynum=5;</h4>
<h4>float anothernum=mynum;</h4>
</blockquote>
<p>This will be fine because the floating point type can hold all the values supported by the integer type.</p>
<p>If I have this statement (narrowing)</p>
<blockquote>
<h4>double mynum = 3.5;<br />
float thenum = mynum;</h4>
</blockquote>
<p>the compiler will complain.</p>
<p><strong>Cannot implicitly convert type &#8216;double&#8217; to &#8216;float&#8217;. An explicit conversion exists (are you missing a cast?) </strong></p>
<p>The compiler is basically saying &#8220;Is there any chance you are discarding information?&#8221;</p>
<p>But you can cast the value by using this statement.</p>
<blockquote>
<h4>double mynum = 3.5;<br />
float thenum = (float)mynum;</h4>
</blockquote>
<p>This is an explicit conversion and I say in simple words to the compiler, that I take the responsibility for the possible data loss.</p>
<p>For reference types, if we have a situation like this, where the derived type (Student) is converted to base type (Person), we have imlicit conversion which is safe.</p>
<blockquote>
<h4>Student thestudent = new Student();</h4>
</blockquote>
<p>while if we type this:</p>
<blockquote>
<h4>Person theperson=new Person();</h4>
</blockquote>
<p>this will fail and we must explicitly cast it to the <strong>Student</strong> type, like this.</p>
<blockquote>
<h4>Person theperson=new Person();<br />
Student thestudent = (Student)theperson;</h4>
</blockquote>
<p>Hope it helps. If you need the source code, leave a comment and I will email it to you.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/06/21/object-oriented-programming-concepts-with-c3-0/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;h=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;Title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;title=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F06%2F21%2Fobject-oriented-programming-concepts-with-c3-0%2F&amp;t=Object%20Oriented%20Programming%20Concepts%20with%20C%233.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
Posted in asp.net, C#, c# 3.0, Visual Studio 2008 Tagged: C#3.0, Object oriented programming, OOP <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/904/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=904&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/06/21/object-oriented-programming-concepts-with-c3-0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/06/gotodef.jpg" medium="image">
			<media:title type="html">go to def</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a simple application with Blend and Visual Studio</title>
		<link>http://dotnetstories.wordpress.com/2009/04/26/building-a-simple-application-with-blend-and-visual-studio/</link>
		<comments>http://dotnetstories.wordpress.com/2009/04/26/building-a-simple-application-with-blend-and-visual-studio/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 20:09:09 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[general .net]]></category>
		<category><![CDATA[expression blend]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[window forms]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=887</guid>
		<description><![CDATA[differences between wpf and window forms. A small example using xaml, expression blend and visual studio.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=887&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have dedicated lots of time recently to understand <a href="http://msdn.microsoft.com/en-us/netframework/aa663326.aspx" target="_blank">WPF</a>applications and the large WPF API.</p>
<p>I have been working with window forms applications for many years and I wanted to have a look at this rather new technology, which is a brand new way of building desktop and <a href="http://en.wikipedia.org/wiki/Rich_Internet_application" target="_blank">RIA</a> applications.</p>
<p>There is a lot of stuff one must learn and along with WPF API and Visual Studio, <a href="http://en.wikipedia.org/wiki/Microsoft_Expression_Blend" target="_blank">Microsoft Blend </a>is almost a necessity to explore and learn.</p>
<p>I will create a small application with Blend and Visual Studio in this post.</p>
<p>But I think it is very important to understand why Microsoft created WPF and the accompanying tools and what are the differences between WPF and Window forms applications.</p>
<p>Let&#8217;s start with the differences between WPF and Win forms</p>
<ol>
<li>Window forms was built on top of  2 lower APIs User and User 32(newest version) and <a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface" target="_blank">GDI</a></li>
</ol>
<p>WPF is built on top of <a href="http://en.wikipedia.org/wiki/DirectX" target="_blank">DirectX</a>. We could design-draw an application using User32 and GDI libraries but we could never do things like 3-D effects, transparency, shadows. We can do that with DirectX.WPF is relying on DirectX.User32 and GDI are rendered via the CPU.</p>
<p>DirectX utilises the <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit" target="_blank">GPU</a>.Almost all PCs nowadays have integrated GPUs and with WPF we can harness that extra processing power.So it was natural for Microsoft to implement and provide us with an API , WPF in this case, to take advantage of the new capabilities of graphic cards.The WPF application when it starts it checks to see on what kind of machine it executes and decides if it needs to downgrade certain effects.</p>
<p>2. <a href="http://msdn.microsoft.com/en-us/library/ms752059.aspx" target="_blank">XAML</a> is used to define the WPF objects and is built on top of WPF API. It is an XML-style language. Expression Blend is just a tool in assisting developers-designers in the creation of User Interfaces. Expression Blend generates XAML code. The business rules and the back end access is still  implemented with .Net languages</p>
<p>3. With WFP we have the addition of <strong>New Navigation Project types</strong>. In WPF we have the option to create page based applications. For example we can navigate back and forth in our application like in a web based interface.</p>
<p>4. The layout of the controls in WPF is quite different.WPF&#8217;s default layout is relative. In a WPF application it is much easier to resize and reposition controls</p>
<p>5. With WPF we have much better tools at our disposal when dealing with audio and video within our applications</p>
<p>6. We can have fantastic and really impressive animations in our WPF applications, somthing we could not really do easily with window forms.</p>
<p>7. We have &#8220;Themes and Skins&#8221; in WPF. It was very difficult in Window forms applications to keep all the controls (e.g buttons in all forms) to have the same background color.In WPF we can do that through styles and templates.</p>
<p>Let&#8217;s start building our first application using Blend and Visual Studio. I assume that you have Visual Studio 2008 installed.Visual Studio 2008 express editions can be downloaded from <a href="http://www.microsoft.com/express/download/" target="_blank">here</a>. Download the Visual C#  2008 Express edition.</p>
<p>If you need to download Expression Blend 2.0 click <a href="http://www.microsoft.com/Expression/products/Overview.aspx?key=blend" target="_blank">here</a>. Bear in mind, this is a trial software&#8230;</p>
<p>1) Launch Visual Studio 2008 and as a project template choose &#8220;WPF application&#8221;. Select C# as the labguage of development.</p>
<p>2) Save your project with a name e.g &#8220;myfirstWPFapp&#8221;</p>
<p>3) Launch Expression Blend 2. Open the &#8220;myfirstWPFapp&#8221; from Blend by clicking <strong>File-&gt;Open -&gt; Project/Solution</strong></p>
<p>4) Our solution is opened both from Visual Studio and Expression Blend. I will use Expression Blend to create the basic user interface. Drag and drop a button on the . You can resize it if you want, give it a name and set it a color. You can do all that from the Properties window. Spend some time to familiarise yourselves with the Blend IDE.</p>
<p>5) Click the &#8220;Window&#8221; option which is a top level menu in Blend.Check the &#8220;Interaction&#8221; option.The Interaction window is now visible.</p>
<p>6) Add a new event in the interaction window. When the button is clicked a new event is raised. You will see a message from Blend saying &#8220;No storyboard exists for you to begin or to control.One will be created.&#8221; Click <strong>OK</strong></p>
<p>Have a look at the image below.<a href="http://dotnetstories.files.wordpress.com/2009/04/blend.jpg"><img class="aligncenter size-medium wp-image-890" title="blend" src="http://dotnetstories.files.wordpress.com/2009/04/blend.jpg?w=300&#038;h=187" alt="blend" width="300" height="187" /></a></p>
<p>7) Now we have a new window appearing in our IDE, <strong>Objects and Timeline</strong>. Notice also that on the top left corner the statement &#8220;Timeline recording is on&#8221; is written.</p>
<p>8) From the &#8220;Objects and Timeline&#8221; window-pane drag a line(yellow line) until you reach 1.5 seconds in time in order to create a timeline</p>
<p>9) Now select the corner of the button and try to flip-rotate it 180 degrees.It is very easy to do. Just select the button and wait until the curly double-head arrows appear.Then just rotate it.</p>
<p>10) Now add another 1.5 seconds in the timeline, by dragging the yellow line to the 3 seconds interval. Rotate the button back to its original position.</p>
<p>11) Hit F5 to run your application. Click on the button to see that rotates</p>
<p>12) Close Expression Blend. Switch to Visual Studio. Reload and click &#8220;Yes&#8221; when asked to save the solution.</p>
<p>13) Run your application from Visual studio by hitting F5. You see the same results.</p>
<p>14) Double click on the button. In the code behind file in the event handler subroutine, simply type</p>
<h4>MessageBox.Show(&#8220;This is a first WPF application&#8221;);</h4>
<p>15) Run your application again. When you click your button, first the message pops us and then the animation starts to unfold.</p>
<p>So in a much more complex application than this, the designer can create the UI and the stunning effects while the developer can concentrate on the business rules and the data access.</p>
<p>Finally it is worth pointing out that</p>
<p>1) We can have  Windows Presentation Foundation inside existing Win32 code and vice versa we can have existing Win32 code inside Windows Presentation Foundation</p>
<p>2) WPF is interoperable with Window forms  through the use of the ElementHost and WindowsFormsHost classes.</p>
<p>And remember that Window forms are here to stay despite all the things I have been pointing out in this post.As things stand now, most users are familiar with the &#8220;look and feel&#8221; of window forms and there are more third party tools-components for window forms.</p>
<p>WPF is a new way of delivering excellent functionality with more style!!!!!!!!!</p>
<p>Hope it helps!!!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/04/26/building-a-simple-application-with-blend-and-visual-studio/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;h=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;Title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;title=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F04%2F26%2Fbuilding-a-simple-application-with-blend-and-visual-studio%2F&amp;t=Building%20a%20simple%20application%20with%20Blend%20and%20Visual%20Studio" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
Posted in general .net, Visual Studio 2008, WPF, XAML Tagged: expression blend, RIA, window forms, WPF, XAML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/887/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/887/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/887/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/887/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/887/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/887/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/887/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/887/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/887/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/887/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=887&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/04/26/building-a-simple-application-with-blend-and-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/04/blend.jpg?w=300" medium="image">
			<media:title type="html">blend</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Create an XML file using LINQ and import XML data into an Excel spreadsheet</title>
		<link>http://dotnetstories.wordpress.com/2009/03/31/create-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet/</link>
		<comments>http://dotnetstories.wordpress.com/2009/03/31/create-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 19:39:35 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Linq to Sql]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML Literals]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=866</guid>
		<description><![CDATA[In this post I will try to create an excel file and populate the rows and columns with XML data that I read from a relational database table. I will use Visual Studio 2008,vb and in particular XML Literals and LINQ to SQL classes.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=866&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hey all,</p>
<p>You must think that this post title is a rather long one. Yes it is, but the concepts are rather easy and I have been posting lots of stuff regarding LINQ to SQL,VB.Net, XML Literals, e.t.c.</p>
<p>A friend of mine had a project which required to get some data from an SQL Server database table, create an XML document from the relational data and import it to an excel file. Another thing to bear in mind here is that we needed to create the excel file programmatically.</p>
<p>I tried to help him out and then thought that it might be a good idea to write a post about the solution I proposed.</p>
<p>So I will try to show all these, by (a hands-on example) building a windows form application using VB 2008(9.0).</p>
<p>I am going to use Visual Studio 2008 professional but Visual studio 2008 Express edition will do just fine.You can download Visual Studio 2008 from <a href="http://www.microsoft.com/express/vwd/" target="_blank">here</a> .</p>
<p>Obviously for this example we will need a database. I will use the <strong>Pubs</strong> database. This is a well known database and many people are familiar with its schema.You can download the <strong>Pubs</strong> database from this <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46a0-8da2-eebc53a68034&amp;DisplayLang=en" target="_blank">link</a>. If you need some help on how to install the database have a look <a href="http://www.codeproject.com/KB/database/InstallingNorthwindAndPub.aspx" target="_blank">here</a> .</p>
<p>I have installed SQL Server 2008 Standard edition in my PC. SQL Server 2008/2005 Express editions will work just fine.You can download SQL Server 2008 Express edition from this <a href="http://www.microsoft.com/express/sql/register/" target="_blank">link. </a> I have attached the Pubs database in my local instance of the SQL Server.</p>
<p>In order to follow along you must have all the above running smoothly in your pc.It will be great for you in order to better understand what I am about to show you, If you are familiar with LINQ to SQL and XML Literals.</p>
<p>If you want to read another post of mine regarding XML Literals click <a href="http://dotnetstories.wordpress.com/2008/11/21/xml-literals-and-visual-basic-90/" target="_blank">here</a> .</p>
<p>If you want to read another post of mine regarding LINQ to SQL click <a href="http://dotnetstories.wordpress.com/2008/07/01/linq-to-sql-querying-the-pubs-database/">here<br />
</a></p>
<p>So let&#8217;s start&#8230;</p>
<p>1) Lauch Visual Studio 2008</p>
<p>2) Create a new project. From the available templates choose &#8220;Windows form Application&#8221;. Make sure VB is selected as your language of choice for this project.</p>
<p>3) Give your project a suitable name, e.g &#8220;sqltoxmlandimporttoexcel&#8221;</p>
<p>4) We will create the excel file programmatically first.In the form (Form1) just drag and drop a button on it. Name it &#8220;btnCreateExcel&#8221;.</p>
<p>5) Go to your c:\ drive and create a folder.Name this folder as you want. I have named this new folder after my name, thus nikos. So I have a path of &#8220;c:\nikos&#8221;. In this folder I will place the excel file that I will create programmatically.</p>
<p>6) Double click on the button. In the event handling routine that is created by VS 2008 for us, paste the code below</p>
<h4>Dim xlApp As excel.Application</h4>
<h4>Dim xlWorkBook As excel.Workbook</h4>
<h4>Dim xlWorkSheet As excel.Worksheet</h4>
<h4>xlApp = New excel.ApplicationClass</h4>
<h4>xlWorkBook = xlApp.Workbooks.Add</h4>
<h4>xlWorkSheet = xlWorkBook.Sheets(&#8220;sheet1&#8243;)</h4>
<h4>xlWorkSheet.Cells(1, 1) = &#8220;XML Code starts here&#8221;</h4>
<h4>xlWorkSheet.SaveAs(&#8220;C:\nikos\mydataxml.xls&#8221;)</h4>
<h4>xlWorkBook.Close()</h4>
<h4>xlApp.Quit()</h4>
<h4>xlApp = Nothing</h4>
<h4>MsgBox(&#8220;Your Excel file has been created successfully&#8221;)</h4>
<p>As you see I have called my excel workfile, &#8220;<em>mydataxml.xls</em>&#8220;</p>
<p>7) You must do 2 two things in order for this code to run. First you must add a reference to the Microsoft Excel Interop Library which can be found in the COM components tab.</p>
<ul>
<li>Right-click on your Project and select &#8220;Add reference&#8221; and then from the &#8220;Add reference&#8221; window, Select the COM tab. Scroll down till you find the <strong>Microsoft Excel 11.0 Object Library</strong> and click <strong>OK</strong>.</li>
</ul>
<p>Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/excel-com-library-new.jpg"><img class="aligncenter size-full wp-image-869" title="excel-com-library-new" src="http://dotnetstories.files.wordpress.com/2009/03/excel-com-library-new.jpg?w=460&#038;h=286" alt="excel-com-library-new" width="460" height="286" /></a></p>
<ul>
<li>Add this line of code just above the &#8220;Public Class Form 1&#8243;</li>
</ul>
<h4>Imports excel = Microsoft.Office.Interop.Excel</h4>
<h4>Public Class Form1</h4>
<p>8) Run your application by hitting F5. Click on the button and then check on your specified folder to see if the excel file has been created.</p>
<p>9) Now we need to query our database table. We are going to use this by using LINQ to SQL. Go to your Solutions Explorer, select your project and then right click and choose &#8220;Add new item&#8221; and choose LINQ to SQL classes. Name the .dbml file as <strong>Pubs.dbml</strong>. If you open the <strong>Pubs.dbml</strong> file, you will see the O-R designer surface.From your <strong>Server Explorer</strong> window, click to the <strong>Connect to Database</strong> button. Select the Sql Server instance name and select the Pubs database and hit the OK button.See the picture below:</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/add-connection-new.jpg"><img class="aligncenter size-full wp-image-873" title="add-connection-new" src="http://dotnetstories.files.wordpress.com/2009/03/add-connection-new.jpg?w=459&#038;h=286" alt="add-connection-new" width="459" height="286" /></a></p>
<p>10) After establishing the connection with the Pubs database, expand the Tables node and drag &#8211; drop the Authors table in the O-R designer surface. An &#8220;Author&#8221; data class is automatically created for us.</p>
<p>11) Place another button on your form. Name the button &#8220;CreateXML&#8221;. Double click on the button. In the event handling routine type the code below. I am trying to get all the rows of the authors table and save them in an .xml file.</p>
<h4>Dim mydb As New PubsDataContext</h4>
<h4>Dim myauthors = &lt;authors&gt;</h4>
<h4>&lt;%= From author In mydb.authors Select _<br />
&lt;author&gt;<br />
&lt;lname&gt;</h4>
<h4>&lt;%= author.au_lname %&gt;<br />
&lt;/lname&gt;<br />
&lt;fname&gt;</h4>
<h4>&lt;%= author.au_fname %&gt;<br />
&lt;/fname&gt;</h4>
<h4>&lt;phone&gt;</h4>
<h4>&lt;%= author.phone %&gt;<br />
&lt;/phone&gt;<br />
&lt;address&gt;</h4>
<h4>&lt;%= author.address %&gt;<br />
&lt;/address&gt;<br />
&lt;city&gt;</h4>
<h4>&lt;%= author.city %&gt;<br />
&lt;/city&gt;<br />
&lt;state&gt;</h4>
<h4>&lt;%= author.state %&gt;<br />
&lt;/state&gt;</h4>
<h4>&lt;zip&gt;</h4>
<h4>&lt;%= author.zip %&gt;<br />
&lt;/zip&gt;</h4>
<h4>&lt;contract&gt;</h4>
<h4>&lt;%= author.contract %&gt;<br />
&lt;/contract&gt;</h4>
<h4>&lt;/author&gt; %&gt;<br />
</h4>
<h4>
&lt;/authors&gt;</h4>
<h4>
myauthors.Save(&#8220;c:\nikos\myxmldata.xml&#8221;)</h4>
<p>12) As you see what I am doing is pretty simple. I type XML statements that form the structure of my XML document using LINQ to SQL expressions to query the relational data.If you run your application and click the &#8220;CreateXML&#8221; button, you will have in your specified folder (c:\nikos\ , in my case) a document called &#8220;myxmldata.xml&#8221;. Browse to the specified folder and select the &#8220;myxmldata.xml&#8221;, right-click on this file and <strong>Open it with</strong> Internet Explorer. You will see all 23 rows of data that resides in the Authors table to be represented as nodes in our newly created xml file.</p>
<p>13) So now we are on the final part of our solution. Yes you guessed it!!! We will place another button on the form. We will call it &#8220;SaveXMLtoExcel&#8221;. By clicking on this button, all the data from the xml file should be placed in the excel file we created in the first steps of this example.</p>
<p>14) Double click on the &#8220;SaveXMLtoExcel&#8221; button and in the event handling routine ,and paste the code below. Do no forget to include the <strong>Imports System.Xml</strong> namespace at the beginning of your Form1.vb file.</p>
<p>In this routine I get an instance of the existing excel file and by using the <strong>XMLReader</strong> class and the <strong>ReadXml</strong> to read the xml data into a dataset.Then I use the dataset to populate the rows and columns of the specific worksheet.</p>
<h4>Dim xlApp As excel.Application<br />
Dim xlWorkBook As excel.Workbook<br />
Dim xlWorkSheet As excel.Worksheet<br />
</h4>
<h4>
Dim ds As New DataSet<br />
Dim xmlFile As XmlReader<br />
Dim i, j As Integer<br />
</h4>
<h4>
xlApp = New excel.ApplicationClass<br />
xlWorkBook = xlApp.Workbooks.Open(&#8220;c:\nikos\mydataxml.xls&#8221;)<br />
xlWorkSheet = xlWorkBook.Sheets(&#8220;sheet1&#8243;)<br />
</h4>
<h4>
xmlFile = XmlReader.Create(&#8220;c:\nikos\myxmldata.xml&#8221;, New XmlReaderSettings())<br />
ds.ReadXml(xmlFile)<br />
</h4>
<h4>
For i = 0 To ds.Tables(0).Rows.Count &#8211; 1<br />
For j = 0 To ds.Tables(0).Columns.Count &#8211; 1<br />
xlWorkSheet.Cells(i + 1, j + 1) = _<br />
ds.Tables(0).Rows(i).Item(j)<br />
Next<br />
Next<br />
</h4>
<h4>
xlWorkSheet.SaveAs(&#8220;C:\nikos\mydataxml.xls&#8221;)<br />
xlWorkBook.Close()<br />
xlApp.Quit()<br />
xlWorkBook = Nothing<br />
xlApp = Nothing<br />
</h4>
<h4>
GC.Collect()</h4>
<p>15) Run your application. Hit the &#8220;SaveXMLtoExcel&#8221; button. Open the excel file and hopefully you will see 23 rows of data that represent <em>authors</em> data</p>
<p>I am sure you can realise that you could combine the whole functionality in one button or routine, but I broke the code into various parts so it is easier to read. I think we have covered lots of things in this post. We talked about XML,XML literals,LINQ to SQL and how to create excel file from XML data.</p>
<p>Hope it helps!!!</p>
<p>Happy reading!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/03/31/create-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;h=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;Title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;title=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F31%2Fcreate-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet%2F&amp;t=Create%20an%20XML%20file%20using%20LINQ%20and%20import%20XML%20data%20into%20an%20excel%20spreadsheet" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in LINQ, MS Office, VB 9.0, Visual Studio 2008 Tagged: Excel, Linq to Sql, VB 9.0, Visual Studio 2008, XML, XML Literals <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/866/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/866/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/866/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/866/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/866/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=866&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/03/31/create-an-xml-file-using-linq-and-import-xml-data-into-an-excel-spreadsheet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/excel-com-library-new.jpg" medium="image">
			<media:title type="html">excel-com-library-new</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/add-connection-new.jpg" medium="image">
			<media:title type="html">add-connection-new</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Create a simple data-centric WPF application</title>
		<link>http://dotnetstories.wordpress.com/2009/03/28/create-a-simple-data-centric-wpf-application/</link>
		<comments>http://dotnetstories.wordpress.com/2009/03/28/create-a-simple-data-centric-wpf-application/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 23:01:37 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Visual basic]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=838</guid>
		<description><![CDATA[I have been asked from some people to write a simple post regarding the younger and more flashy brother of  window forms. WPF is about 1 years old now and gaining ground on developers for building next generation window applications.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=838&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been asked from some people to write a simple post regarding the younger and more flashy brother of  window forms. <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" target="_blank">WPF</a> is about 1 years old now and gaining ground on developers for building next generation window applications. I urge people who are new to WPF to familiarise themselves a little bit with WPF by clicking <a href="http://msdn.microsoft.com/en-gb/library/aa970268.aspx" target="_blank">here</a> .</p>
<p>In this post I am going to do just that through a very practical hands-on example. I am going to use Visual Studio and VB 2008 to build a simple data entry form.</p>
<p>I am going to use the Northwind database as our data store for this example.</p>
<p>Click <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;displaylang=en" target="_blank">here</a> to download the installation scripts. Fire SQL Server 2005/2008 Express Edition or SQL Server Standand edition 2005/2008 and run the scripts. All the tables and their related data is now available for us to use.</p>
<p>1) Launch Visual Studio 2008 professional or express edition</p>
<p>2) Create a new project by choosing from the available templates <strong>WPF application</strong> (choose VB as your language of development)</p>
<p>3) Name your application <strong>myfirstWPFapp. </strong></p>
<p>4) Click the <strong>Data</strong> from the menu and then click <strong>Show Data Sources</strong>.Click on the <strong>Add New Data Source</strong> link.</p>
<p>5) Select <strong>Database</strong> from the Dialog window and click <strong>Next .<br />
</strong></p>
<p>6) Create a new connection string by clicking the <strong>New Connection</strong>. In the new window that appears choose the SQL Server name to connect to. This is of course the server that you installed the Northwind database. In my case it is <strong>FOFO-PC\SQLEXPRESS</strong> and then select the database from the dropdown list (Northwind of course). Test the connection and click <strong>OK</strong> to close the window.</p>
<p>7) CLick <strong>Next</strong> on the data source configuration wizard and save the connection string as <strong>NorthwindConnectionString. </strong>Click <strong>Next</strong>.</p>
<p>8) In the next step of the wizard from all the database objects expand the table node and select <strong>Customers</strong>. Name the dataset <strong>CustomersDataset</strong>. Click <strong>Finish</strong>.</p>
<p>9) In the <strong>Window1.xaml</strong> just drag and drop 4 button(on the right hand corner) controls from the Toolbox on your Wpf form. We want to add, delete,save and cancel(cancel the data that we are currently inserting) data from our <strong>Customers</strong> table. Name the buttons accordingly by changing their <strong>Name</strong> property for each one of them. I named them for example <strong>btnSave,btnCancel</strong>, e.t.c.Give them an appropriate label by changing  the <strong>Content</strong> property for each one of them.Change from the properties window some properties e.g background,foreground colors. Align the buttons and make them the same width. This is a good practice.These changes will be saved in the XAML code that you can see in the lower half of the window. We will not focus too much on the design issues in this post.</p>
<p>10) Drag and drop 7 label controls on the WPF form. Name them e.g <strong>lblCustomerID,lblCompanyname</strong> <strong>lblName,lblCity,lblCountry,lblRegion,lblPhone</strong>. Give them an appropriate text by changing  the <strong>Content</strong> property for each one of them.Change from the properties window some properties e.g background,foreground colors. Align them and make them the same width by setting the <strong>width </strong>property for each one of them to &#8220;100&#8243;.</p>
<p>11) Drag and drop 5 textboxes on the Wpf form.Name them e.g <strong>txtCustomerID</strong>, <strong>txtCompanyName,txtName,txtCity,txtCountry,txtRegion,txtPhone</strong>. Change from the properties window some properties e.g background,foreground colors. Align them and make them the same width by setting the <strong>width </strong>property for each one of them. Align the label controls and the textbox controls using the visual alignment controls. Resize the formif you want.</p>
<p>12) We have not finished yet. We must provide some sort of navigation controls to our application. In WPF applications we do not have ready controls(navigators) like we did with normal window forms. Drag and drop 4 button(on the left hand corner) controls from the Toolbox on your Wpf form. We want to allow users to navigate to the first,last,previous and next record from our <strong>Customers</strong> table. Name the buttons accordingly by changing their <strong>Name</strong> property for each one of them. I named them for example <strong>btnfirst,btnlast</strong>, e.t.c.Give them an appropriate label by changing  the <strong>Content</strong> property for each one of them.Change from the properties window some properties e.g background,foreground colors if you want. Align the buttons and make them the same width.If you have followed along every step you must have something similar with this picture below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/wpf-new-1.jpg"><img class="aligncenter size-full wp-image-857" title="wpf-new-1" src="http://dotnetstories.files.wordpress.com/2009/03/wpf-new-1.jpg?w=460&#038;h=285" alt="wpf-new-1" width="460" height="285" /></a></p>
<p>13) That seemed like a lot of work&#8230; Ok, so now we are ready to finally do our databinding tasks. We obviously need to populate the textbox controls with data from our <strong>Customer</strong> database table through our <strong>CustomersDataSet</strong> object and the <strong>Customers Data Table</strong> object.If you have done databinding using window forms , you may think that we simply drag and drop the fields from the Data Sources window on the wpf form. We can not do that. But we can databind the textboxes to their respective values from the database from XAML code. We do that by telling each textbox <strong>Text</strong> property that is bound to the relevant field in the table. In the XAML pane we locate the first textbox, and we bind it to the CustomerID field using this code(i just typed the code in brown color):</p>
<p>&lt;TextBox Grid.Column=&#8221;1&#8243; Grid.Row=&#8221;1&#8243; Height=&#8221;23&#8243; Margin=&#8221;61,13,103,0&#8243; Name=&#8221;txtCustomerID&#8221; VerticalAlignment=&#8221;Top&#8221; <span style="color:#800000;"><strong>Text=&#8221;{Binding Path=CustomerID}&#8221; </strong></span> /&gt;</p>
<p>You do that for the remaining 6 textbox controls.</p>
<p>14) Now we need to load the data in our form. We must write some code in our code behind file in the appropriate event. This is the Window_Loaded event handler routine. We must create some variables for our dataset,tableadapter and tableadaptermanager. You can do this by writing something like that</p>
<h4>Dim customerdataset As New CustomersDataSet</h4>
<h4>Dim customeradapter As New CustomersDataSetTableAdapters.CustomersTableAdapter</h4>
<h4>Dim customermanager As New CustomersDataSetTableAdapters.TableAdapterManager</h4>
<p>Now inside the event handling routine you have</p>
<h4>Private Sub myfirstWPFAPP_Loaded(ByVal sender As Object, ByVal e As    System.Windows.RoutedEventArgs) Handles Me.Loaded<br />
</h4>
<h4>
Me.customeradapter.Fill(Me.customerdataset.Customers)<br />
</h4>
<h4>
Me.DataContext = Me.customerdataset.Customers<br />
</h4>
<h4>
End Sub</h4>
<p>15) If you hit F5 and run your application you will see the first row(only the fields we specified, not all of them) of the <strong>Customers</strong> Table loaded into the 7 textboxes. That is great!!! But we do not need just the data for one record, we need all the records. For this we need to write some code in our navigation controls. In order to do that we need an object to navigate the data collection. This object is the <strong>CollectionView</strong> object.</p>
<p>We create a variable of that data type e.g</p>
<h4>Dim myview As CollectionView</h4>
<p>and inside the form Loaded Event(myfirstWPFAPP_Loaded)we type the following line to give a value to our object</p>
<h4>Me.myview = CollectionViewSource.GetDefaultView(Me.customerdataset.Customers)</h4>
<p>16) Double Click the button that you named &#8220;First&#8221;. An event handling routine is created. Add this line of code</p>
<h4>Me.myview.MoveCurrentToFirst()</h4>
<p>So the full code is:</p>
<h4>Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As  System.Windows.RoutedEventArgs) Handles btnfirst.Click</h4>
<h4>Me.myview.MoveCurrentToFirst()</h4>
<h4>End Sub</h4>
<p>17) Double Click the button that you named &#8220;Previous&#8221;. An event handling routine is created. Add these three lines of code inside it. In this case we check with a very simple If statenement if we are on the first record. If not we can go to the previous one.</p>
<h4>If Me.myview.CurrentPosition &gt; 0 Then</h4>
<h4>Me.myview.MoveCurrentToPrevious()<br />
</h4>
<h4>
End If</h4>
<p>18) Double Click the button that you named &#8220;Next&#8221;. An event handling routine is created. Add these three lines of code inside it. Here we check if we are in the last row of our table. If not , we move to the next record.</p>
<h4>If Me.myview.CurrentPosition &lt; Me.myview.Count &#8211; 1 Then</h4>
<h4>Me.myview.MoveCurrentToNext()<br />
</h4>
<h4>
End If</h4>
<p>19) Double Click the button that you named &#8220;Last&#8221;. An event handling routine is created. Add this line of code inside it.</p>
<h4>Me.myview.MoveCurrentToLast()</h4>
<p>20) Run your application by hitting F5. Make sure that the navigation buttons operate as desired.</p>
<p>21) Yes it is now time to write some more code so our ,cancel,save,delete,add buttons to be operational.Double Click on the &#8220;Delete&#8221; button on your form. An event handling routine is created. Add these 4 lines of code inside it.</p>
<h4>If Me.myview.CurrentPosition &gt; -1 Then<br />
Dim row = CType(Me.myview.CurrentItem, System.Data.DataRowView).Row<br />
row.Delete()<br />
</h4>
<h4>
End If</h4>
<p>We check to see that we are in a record and that our table is not empty. Then we must get the row that is currently in view and then we simply delete it. I want to highlight something here. This Customers table is related via a foreign key constraint to the Orders table which is another table of the Northwind database. If you go to delete one record from the Customers table that has placed an order, then you will receive an error. In order to test the &#8220;Delete&#8221; button just add a brand new customer using the &#8220;Add&#8221; button first.</p>
<p>22) Double Click on the &#8220;Add&#8221; button on your form. An event handling routine is created. Add these 3 lines of code inside it.</p>
<h4>Dim row = Me.customerdataset.Customers.NewCustomersRow</h4>
<p>&#8216; because these fields do not allow nulls we specify some values</p>
<h4>row.CustomerID = &#8220;[mid]&#8220;<br />
row.CompanyName = &#8220;[my company name]&#8220;</h4>
<h4>Me.customerdataset.Customers.AddCustomersRow(row)</h4>
<h4>Me.myview.MoveCurrentToLast()</h4>
<p>23) Double Click on the &#8220;Cancel&#8221; button on your form. An event handling routine is created. Add this line of code inside it.</p>
<h4>Me.customerdataset.RejectChanges()</h4>
<p>24) Double Click on the &#8220;Save&#8221; button on your form. An event handling routine is created. Add these 7 lines of code inside it.</p>
<h4>Try<br />
If Me.customerdataset.HasChanges Then<br />
</h4>
<h4>
Me.customeradapter.Update(Me.customerdataset)<br />
</h4>
<h4>
End If</h4>
<h4>Catch ex As Exception<br />
MsgBox(ex.Message)<br />
</h4>
<h4>
End Try</h4>
<p>25)  Run your application. Add a new customer by clicking the &#8220;Add&#8221; Button and filling in the data and click the &#8220;Save&#8221; button. A new customer is in the database. Then click the &#8220;Delete&#8221; Button while the newly created customer row is active. Click the &#8220;Save&#8217; button again.The customer is deleted. Check these changes in your actual database.</p>
<p>Hope it helps. If you need the source code email me at nkantzelis@q-training.gr</p>
<p>Happy browsing!!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/03/28/create-a-simple-data-centric-wpf-application/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;h=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;Title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;title=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F28%2Fcreate-a-simple-data-centric-wpf-application%2F&amp;t=Create%20a%20simple%20data-centric%20WPF%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" alt="Add to Furl" /></a></p>
Posted in VB 9.0, Visual Studio 2008, WPF, XAML Tagged: Visual basic, Visual Studio 2008, WPF, XAML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/838/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=838&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/03/28/create-a-simple-data-centric-wpf-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/wpf-new-1.jpg" medium="image">
			<media:title type="html">wpf-new-1</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>A thorough Introduction to Integration Services</title>
		<link>http://dotnetstories.wordpress.com/2009/03/03/a-thorough-introduction-to-integration-services/</link>
		<comments>http://dotnetstories.wordpress.com/2009/03/03/a-thorough-introduction-to-integration-services/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 16:40:07 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2005]]></category>
		<category><![CDATA[Integration Services]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=823</guid>
		<description><![CDATA[SSIS is an automation tool-component that is part of SQL Server 2005 and SQL Server 2008. It replaces DTS which has been a set of tools that were useful to DBAs to import, export, and transform data. DTS was included in all previous versions of SQL Server up to 2000.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=823&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this rather huge post I will try to explain and give valuable references when appropriate, regarding the use and functionality of Integration Services or SSIS for short. There will be other posts following regarding SSIS.</p>
<p>I will be using SQL Server 2008 for the various examples but you can use SQL Server 2005. It will not be a problem.</p>
<p>I will try to explain the main concepts of SSIS. More specifically I will try to talk about</p>
<ul>
<li>Tasks integrated Services are best suited for</li>
<li>What the major components of SSIS are</li>
<li>The techniques that one can use to build,debug and deploy transformations with Business Intelligence Development Studio</li>
</ul>
<p>SSIS is an automation tool-component that is part of SQL Server 2005 and SQL Server 2008. It replaces <a href="http://msdn.microsoft.com/en-us/library/cc917688.aspx" target="_blank">DTS</a> which has been a set of tools that were useful to DBAs to import, export, and transform data. DTS was included in all previous versions of SQL Server up to 2000.SSIS is only available in the  &#8220;Standard&#8221; and &#8220;Enterprise&#8221; editions.</p>
<p>It is used for</p>
<ul>
<li>Moving data from one database to another database</li>
<li>Copy database to an excel file or a text file</li>
<li>Extract data from a data source, manipulate it,transform it and import it in a database</li>
<li>Converting between various data types</li>
<li>Merging columns into new or existing columns</li>
</ul>
<p>The type of operation that we perform with SSIS is called <a href="http://en.wikipedia.org/wiki/Extract,_transform,_load" target="_blank">ETL</a>.</p>
<p>To access information related to SSIS from the msdn site click <a href="http://msdn.microsoft.com/en-us/library/ms141026.aspx" target="_blank">here .<br />
</a></p>
<p>For a more complete and sound definition you can click <a href="http://en.wikipedia.org/wiki/SQL_Server_Integration_Services" target="_blank">here</a> and see what Wikipedia says about SSIS.</p>
<p>So to recap these are the main tasks that SSIS are used for:</p>
<ul>
<li>Merging data from multiple sources. I know many people out there, will claim that they can do that with writing code in a .net language. Yes of course one can do that. But it takes more time and one will need lots of time for debugging and testing purposes. SSIS provide wizards and components which are configured to do exactly that.</li>
</ul>
<ul>
<li>Populate data warehouses and data stores. This means that SSIS is a great tool for getting data from a OLTP database and insert it into OLAP data store</li>
</ul>
<ul>
<li>Cleaning and validating the data in the database</li>
<li>Build business intelligence logic into data transformation</li>
<li>Automate administrative tasks like database back up, delete,copy database objects</li>
</ul>
<p>Now that all the declarations are out of the way, let&#8217;s review the necessary tools for creating,debugging,deploying and managing SSIS packages. The two main tools are</p>
<ul>
<li>Business Intelligence Development Studio</li>
<li>SQL Server Management Studio</li>
</ul>
<p>In order to create a SSIS package you must create a new SSIS integration project.</p>
<p>In order to create the project you need to fire up BIDS(Business Intelligence Development Studio). Then select <strong>New Project</strong> and from the Project type window select &#8220;Business Intelligence Projects&#8221;. From the templates window select the <strong>Integration Services Project</strong>. Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/bids.jpg"><img class="aligncenter size-full wp-image-825" title="bids" src="http://dotnetstories.files.wordpress.com/2009/03/bids.jpg?w=459&#038;h=308" alt="bids" width="459" height="308" /></a></p>
<p>When you click <strong>OK</strong> in the <em>New Project</em> window, you will have in your screen something similar like the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/bids1.jpg"><img class="aligncenter size-full wp-image-827" title="bids1" src="http://dotnetstories.files.wordpress.com/2009/03/bids1.jpg?w=460&#038;h=287" alt="bids1" width="460" height="287" /></a></p>
<p>In this simple project we have just created, there are 4 folders in it anda a sample Package called <strong>Package.dtsx</strong>.</p>
<p>A package is the main container for tasks that are part of a complete unit of work.</p>
<p>A Package contains objects that you can simply drag and drop from the Toolbox window and processes that control the sequence of those objects. The objects can be</p>
<ul>
<li>Control flow objects which are commonly referred as tasks, like copying files and sending emails</li>
<li>Data flow objects are called transformations. You extract data using <strong>data sources</strong>, you transform tha data (in memory) using <strong>data transformations</strong> and load data using <strong>data destinations</strong>.</li>
</ul>
<p>There are 3 main processes. These Processes are represented by the 3 different tabs in the <strong>Package.dtsx[Design]</strong>.</p>
<ul>
<li>Control Flow. The Control Flow tab allow us to drag and drop control flow items from the Toolbox to the designer surface and then connect them together.</li>
<li>Data Flow. Their mission is to retrieve data from a data source and save it to a target destination</li>
<li>Event Handlers. This allow us to perform various tasks at specific points in time during the lifetime of a package.</li>
</ul>
<p>I will start a new practical example to demonstrate the above topics. I need a database to do that. I will use the <strong>AdventureWorksLT</strong> database.SQL Server  2005-2008 does not install sample databases by default due to security reasons.  We must download them and install them separately. You can download this free  database from the codeplex website. <span><a href="http://www.codeplex.com/" target="_blank">Codeplex</a> is the project hosting site for Microsoft SQL Server  Samples and Community Projects.The down-loadable file, will  be a .msi file that  you need to run and after successfully doing that, the .mdf and .ldf files will  be placed somewhere on your hard disk.</span> Then you can attach them to your  local instance of your SQL Server from SQL Server Management Studio.</p>
<ul>
<li>For those that have Sql Server 2005 installed they need to go and download  the file ,”AdventureWorksLT.msi”, from <a href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004" target="_blank">here</a></li>
<li>For those that have Sql Server 2008 installed they need to go and download  the file,”SQL2008.AdventureWorks_All_Databases.x86.msi”, from <a href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=18407" target="_blank">here</a></li>
</ul>
<p>So I assume that you have downloaded the correct version of the <strong>AdventureWorksLT</strong> database and attached it to the local instance of your SQL Server. In this example I want to</p>
<ul>
<li>Get data from <strong>Customer</strong> table in my  <strong>AdventureWorksLT</strong> database</li>
<li>Make some transformations on the retrieved rows of the <strong>Customer</strong> table. e.g combine two columns of the table into a new column. Take <strong>FirstName</strong> and <strong>LastName</strong> columns and combine them into a new one.</li>
<li>Save the data to a different format in a .xls file.</li>
</ul>
<p>1) Start BIDS (Business Intelligence Development Studio)</p>
<p>2) Create a new business intelligence project (Integration Services Project) and call it &#8220;TranformCustomers&#8221;</p>
<p>3) Drag and Drop a <strong>Data Flow Task</strong> onto the designer surface.</p>
<p>4) Double click on it and you will immediately be transferred from the <strong>Control Flow</strong> tab to the <strong>Data Flow</strong> tab.</p>
<p>5) Go to your toolbox and drag and drop on the design surface(<strong>Data Flow</strong> tab) a O<strong>LE DB Source</strong> component.</p>
<p>6) Double click the component and in the window that appears (<strong>OLE DB Source Editor</strong>) . Click the button <strong>New</strong></p>
<p>7) Click New again to new window that appears titled <strong>Configure OLE DB Connection Manager</strong></p>
<p>8) In the next window that will appear titled <strong>Connection Manager</strong> find the name of your server</p>
<p>9) Then select the <strong>AdventureWorksLT</strong> database, Hit the &#8220;Test the Connection&#8221; Button and click &#8220;OK&#8221; and then click &#8220;OK&#8221; one more time.</p>
<p>10) In the <strong>OLE DB Source Editor</strong> window make sure that the option <strong>Table or View </strong>is selected.</p>
<p>11) Then select the <strong>SalesLT.Customer</strong> table from the dropdown.</p>
<p>12) Hit the Preview button if you want and click &#8220;OK&#8221;</p>
<p>13) Drag and drop a <strong>Derived Column</strong> component onto the Designer Surface.</p>
<p>14 ) Drag the green arrow from the O<strong>LE DB Source</strong> component to the <strong>Derived Column</strong> component until a connection is established.</p>
<p>15) Double click on the <strong>Derived Column</strong> component. A new window, <strong>Derived Column Transformation Editor</strong>, appears.</p>
<p>16) In this new window under the <strong>Derived Column Name </strong>column, type a name for the new derived column.</p>
<p>17) In the <strong>Expression </strong>type <em>FirstName + &#8221; &#8221; + LastName</em> and then click <strong>OK</strong>.</p>
<p>If you have done everything correctly so far you should have something that looks similar with the picture below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/bids3.jpg"><img class="aligncenter size-full wp-image-831" title="bids3" src="http://dotnetstories.files.wordpress.com/2009/03/bids3.jpg?w=460&#038;h=379" alt="bids3" width="460" height="379" /></a></p>
<p>18) The next step is to define where our transformed data will be located. Drag and drop an <strong>Excel Destination Component</strong> onto the designer surface.</p>
<p>19) Drag the green line-arrow from the  <strong>Derived Column</strong> component to the <strong>Excel Destination </strong>component  until a connection is established.</p>
<p>20) Minimise all the windows. Start Microsoft Excel 2003 or 2007 and create an empty workbook. Name it <strong>Customer.xls</strong> and save it on your desktop. Open the workbook and name the first worksheet <strong>Customer Data</strong>.</p>
<p>21) Double click the <strong>Excel Destination </strong>component. The <strong>Excel Destination Editor</strong> window appears.</p>
<p>22) Click on the <strong>New</strong> button and from the <strong>Excel Connection Manager</strong> window click <strong>Browse</strong> and then navigate to the <strong>Customer.xls </strong>and click <strong>Open</strong> and then <strong>OK</strong>.</p>
<p>23) Hit the <strong>New</strong> Button(<strong>Excel Destination editor </strong>window), next to the <strong>Name of the excel sheet</strong>:</p>
<p>24) In the <strong>Create Table</strong> window change the CREATE TABLE `Excel Destination` to CREATE TABLE `Customer Data` and click OK.</p>
<p>25 ) Hit the Preview button to have a look at the columns.</p>
<p>26) Click <strong>OK </strong>to exit the <strong>Excel Destination editor </strong>window and save your changes to the project</p>
<p>27) Run your project by hitting F5</p>
<p>28) Your package should execute fine and you should have a picture similar like the one below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2009/03/bids4.jpg"><img class="aligncenter size-full wp-image-832" title="bids4" src="http://dotnetstories.files.wordpress.com/2009/03/bids4.jpg?w=460&#038;h=279" alt="bids4" width="460" height="279" /></a></p>
<p>29) Open the <strong>Customer.xls</strong> file from your desktop and see the transformed data in it.</p>
<p>Now let&#8217;s see another way of  creating packages using the Import / Export Wizard.</p>
<p>We will demonstrate how to create a package with a Import / Export Wizard with an example. In this example I want to copy certain tables from one database that resides in my local instance of SQL Server to a new database that I will create and also resides in my local instance of SQL Server. The database will be <strong>AdventureWorksLT.</strong></p>
<p>1) Start BIDS (Business Intelligence Development Studio)</p>
<p>2) Create a new business intelligence project (Integration Services Project) and call it &#8220;Import/Export&#8221;</p>
<p>3) On the <strong>SSIS Packages</strong> folder right-click and select SSIS Import and Export wizard.</p>
<p>4) In the wizard that pops up click <strong>Next</strong>.In this window select the data source. In this example you should use the local intance of your SQL Server and then select the <strong>AdventureWorksLT</strong> database. Then click <strong>Next</strong>.</p>
<p>5) In the next step of the wizard, select the destination. In this example it will be a new database in the same server.</p>
<p>6) Hit the <strong>New</strong> button and in the new window that appears just type &#8220;Mynewdb&#8221; and hit the <strong>OK</strong> button and then click the <strong>Next</strong> button.</p>
<p>7) Select (should be selected by default) the first option in the next step of the wizard.Click <strong>Next</strong>.</p>
<p>8) In the next step of the wizard select as many tables of the database that you want copied to the new database.</p>
<p>9) Click the <strong>Next</strong> button and then click the <strong>Finish</strong> button.</p>
<p>10) if you go back to your project in the BIDS, you will see a new package that was created automatically for us and called <strong>Package1.dtsx. </strong>We did not have to do anything manually only follow the simple steps of the wizard.</p>
<p>11) Run the package by hitting F5.</p>
<p>12) Check that the destination database has all the data you specified in the steps of the wizard.</p>
<p>That is all for now. It is not difficult, is it?</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/03/03/a-thorough-introduction-to-integration-services/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;h=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;Title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;title=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F03%2F03%2Fa-thorough-introduction-to-integration-services%2F&amp;t=A%20thorough%20Introduction%20to%20Integration%20Services" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
Posted in Sql Server, Sql Server 2005, SQL Server 2008 Tagged: Integration Services, Sql Server 2005, SQL Server 2008 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/823/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=823&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/03/03/a-thorough-introduction-to-integration-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/bids.jpg" medium="image">
			<media:title type="html">bids</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/bids1.jpg" medium="image">
			<media:title type="html">bids1</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/bids3.jpg" medium="image">
			<media:title type="html">bids3</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2009/03/bids4.jpg" medium="image">
			<media:title type="html">bids4</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to creating, modifying, executing stored procedures</title>
		<link>http://dotnetstories.wordpress.com/2009/02/28/introduction-to-creating-modifying-executing-stored-procedures/</link>
		<comments>http://dotnetstories.wordpress.com/2009/02/28/introduction-to-creating-modifying-executing-stored-procedures/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 21:15:30 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2005]]></category>
		<category><![CDATA[stored procedures]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=813</guid>
		<description><![CDATA[In this post I am going  to talk about stored procedures in conjuction with an SQL Server database<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=813&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have not been talking too much about databases or database design in this blog. There are some posts but this is not a blog about databases, database design or RDBMS. A brilliant blog for SQL Server databases is <a href="http://blog.sqlauthority.com/" target="_blank">SQL Authority</a> .Here you can find hundreds of articles and scripts for people that use SQL Server as their main RDBMS.</p>
<p>In this post I am going  to talk about stored procedures in conjunction with an SQL Server database.</p>
<p>I always try to write posts based on my day to day experience with people who attend the seminars I happen to be teaching. Some people are confused on why we need them, what they are and what they actually do.</p>
<p>As you know with Visual Studio 2008 and the new framework version (3.5 SP1 included) we have many different models-ways-methodologies that we can access a relational database, or the relational world, as I like to call it.</p>
<p>We have LINQ for example which we can use against any data source.  With LINQ we can express efficient query behavior in a programming language of our choice,  transform the query results into whatever format we desire, and manipulate the results.<br />
LINQ to SQL is an object relational mapping  implementation that allows us to model a relational database using .NET classes.  We can query the database using LINQ, as well as update-insert-delete data from it.<br />
LINQ to SQL designer provides an easy way to model and visualize a database as a LINQ to SQL object model.</p>
<p>So many people thought, &#8220;fantastic, I do not have to know anything about the relational world, database design,T-SQL and database objects.&#8221;</p>
<p>Well that is a huge mistake. For me anyone who is using the .NET platform to create data-driven applications must understand database design and how to manipulate the main database objects like views,triggers,stored procedures,tables,indexes.</p>
<p>You need that because many data driven applications out there do not use LINQ or Entity framework and there is a big chance that even if you create your application with LINQ you will need to utilise stored procedures as LINQ to SQL fully supports transactions, views, and stored procedures.</p>
<p>So you cannot be agnostic regarding the relational world. Having said that, please do learn all the new things that ship with the latest versions of .net framework and refer to data access.</p>
<ul>
<li>I will use SQL Server 2008 Standard edition to write,manipulate and execute some stored procedures. You can use SQL Server 2005 or any of the free SQL Server Express editions</li>
<li>I will use the <strong>AdventureWorksLT</strong> database.SQL Server 2005-2008 does not install sample databases by default due to security reasons. We must download them and install them separately. You can download this free database from the codeplex website. <span><a href="http://www.codeplex.com" target="_blank">Codeplex</a> is the project hosting site for Microsoft SQL Server Samples and Community Projects.The down-loadable file, will  be a .msi file that you need to run and after successfully doing that, the .mdf and .ldf files will be placed somewhere on your hard disk.</span> Then you can attach them to your local instance of your SQL Server from SQL Server Management Studio.</li>
<li>For those that have Sql Server 2005 installed they need to go and download the file ,&#8221;AdventureWorksLT.msi&#8221;, from <a href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004" target="_blank">here</a></li>
<li>For those that have Sql Server 2008 installed they need to go and download the file ,&#8221;SQL2008.AdventureWorks_All_Databases.x86.msi&#8221;, from <a href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=18407" target="_blank">here</a></li>
</ul>
<p>I do not know if you are familiar with the sample databases that are available for us to download and use for free.<span>The <strong>AdventureWorks</strong> database supports standard on-line transaction processing scenarios for a <span style="text-decoration:underline;">fictitious</span> bicycle manufacturer (Adventure Works Cycles). Scenarios include Manufacturing, Sales, Purchasing, Product Management, Contact Management, and Human Resources.</span><strong>AdventureWorksLT</strong> (the database we are going to be using)  is a highly simplified and somewhat denormalized version of the Adventure Works OLTP database focused exclusively on a simple sales scenario. For more information for this database click <a href="http://www.codeplex.com/MSFTDBProdSamples/Wiki/View.aspx?title=AWLTDocs&amp;referringTitle=Home" target="_blank">here.</a></p>
<p>Please before you read more on this post, familiarise yourself  with this database.Have a look at the tables and the relations between the tables. It is not difficult at all.</p>
<p>1) Launch SQL Server Management Studio</p>
<p>2) Connect to the Local Instance of your SQL Server</p>
<p>3) Make the <strong>AdventureWorksLT </strong>database as the current database</p>
<p>4) Open a new query window and type the following simple T-SQL code that follows. Hit the execute button</p>
<h4><em>select * from SalesLT.Customer where CustomerID=21</em></h4>
<p>That will return a row of data from the <em>Customers</em> table. Have a look at the results pane, to see for yourself.</p>
<p>If I want to execute the above T-SQL code many times, I should create a stored procedure. So we can take the code above and create a stored procedure. Type the following</p>
<h4><em>CREATE PROCEDURE uspGetCustomers<br />
AS<br />
select * from SalesLT.Customer where CustomerID=21</em></h4>
<p>Hit the execute button. Congratulations, you have created your first stored procedure.</p>
<p>If you click on the <strong>Programmability -&gt;Stored Procedures</strong> you will see the new database object, you have just created.</p>
<p>5) If you want to execute your new stored procedure, you simply type in the query window</p>
<h4><em>exec </em><em></em><em>uspGetCustomers</em></h4>
<p>and hit the execute button. In the results pane you will get one row of data.</p>
<p>6) If you do not want the message that shows the count of the number of rows affected, in the Messages pane (1 row(s) affected), by the stored procedure , you must alter the stored procedure. How you do that?</p>
<p>7) Type the following</p>
<h4><em>ALTER PROCEDURE uspGetCustomers<br />
AS<br />
SET NOCOUNT ON<br />
select * from SalesLT.Customer where CustomerID=21</em></h4>
<p>Hit the execute button. Then type</p>
<h4><em>exec </em><em></em><em>uspGetCustomers</em></h4>
<p>You will notice that there are no messages created this time.</p>
<p>8) One can delete the stored procedure. The T-SQL to do that is</p>
<h4><em>drop procedure </em><em></em><em></em><em></em><em>uspGetCustomers</em></h4>
<p>do not hit the execute button unless you want it actually deleted!!!</p>
<p>So far we have created,executed,altered  and deleted a stored procedure.</p>
<p>A simple and short definition of a stored procedure could be:</p>
<p><strong>It is a collection of  one or more T-SQL statements that are compiled together and given a name that allows you to call and reuse those sql statements by simply calling that name.</strong></p>
<ol>
<li>You can pass information into the stored procedure as an input parameter</li>
<li>You can retrieve scalar values from a stored procedure using output parameters or return values</li>
<li>A stored procedure can return result sets</li>
<li>Stored procedures can be executed from a user query using the SQL Server Management Studio</li>
<li>Stored procedures can be executed from code, like a .NET application , using ADO.Net or LINQ to SQL as data access technologies.</li>
<li>Stored procedures can call other stored procedures</li>
</ol>
<p>Why we should use stored procedures?What are we gaining from using a stored procedure? We could simply write the T-SQL statements in our .net application, without using a stored procedure.</p>
<ul>
<li>With stored procedures we can implement our  business  rules in a much easier and encapsulated way. When an application wants to access our corporate data through a stored procedure we can be certain that there will be no harm done to our data.</li>
</ul>
<ul>
<li>Stored procedures allows various applications to use the stored procedure and hence share the logic of our application.Of course you can create components-classes and keep the business rules of your application in those components.</li>
</ul>
<ul>
<li>Stored procedures help us to secure our application. We can restrict users to update or delete data in our database. Certain privileges can be granted to different users.</li>
</ul>
<ul>
<li>The possibility of becoming a victim of <a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL injection</a> is almost eliminated with stored procedures.</li>
</ul>
<ul>
<li>We can increase the performance of our application with stored procedures. When we call the the stored procedure many times, the execution plan is reused without having to rebuild the query tree or recompiling the execution plan. The execution plan troubles some people so we better give a short explanation. During the execution of a stored procedure , the query tree is created. A query tree is an internal representation of an     <acronym class="ACRONYM">SQL</acronym> statement where the single parts that it is     built from are stored separately. The query tree is passed to the SQL Server optimiser that compiles and optimises it.The optimiser scans the query tree and it develops a plan that is the best way to execute the data. This is the execution plan and that is what it is executed.</li>
</ul>
<ul>
<li>When a stored procedure is called SQL Server will check if the execution plan exists in the cache and use this, if not it will create a new execution plan. If we have many calls to the stored procedure there is no need to create again a query tree or compile the plan again. Simply the existed execution plan is reused.</li>
</ul>
<p>We have created a very simple stored procedure in our previous example. We will demonstrate how to use a stored procedure with an input parameter which allow us to have more generic-useful stored procedures.</p>
<p>1) Launch SQL Server Management Studio</p>
<p>2) Connect to the Local Instance of your SQL Server</p>
<p>3) Make the <strong>AdventureWorksLT </strong>database as the current database</p>
<p>4) Open a new query window and type the following simple T-SQL code that follows. Hit the execute button</p>
<h4>CREATE PROCEDURE uspGetCustomers<br />
@CustomerID Int<br />
AS<br />
SELECT *<br />
FROM SalesLT.Customer<br />
WHERE CustomerID = @CustomerID</h4>
<p>In this example, I allow the application-user to pass to the procedure the <strong>customerID</strong> and the respective data gets returned for that <strong>customerID</strong>.</p>
<p>5) If you want to execute this procedure you can type in a query window</p>
<h4>exec uspGetCustomers 18</h4>
<p>6) You can have a stored procedure with 2 input parameters. Type the following T-SQL in a query window and hit the execute button. In this procedure we try to get the products with  their color and categories specified as input parameters.</p>
<h4>CREATE PROCEDURE uspGetByColorAndCategory<br />
@Color NVARCHAR(15),<br />
@ProductCategoryID INT<br />
AS<br />
SELECT ProductID, Name, ProductNumber<br />
FROM SalesLT.Product<br />
WHERE Color = @Color<br />
AND ProductCategoryID = @ProductCategoryID</h4>
<p>7) If you want to execute this stored procedure, you can type</p>
<h4>exec uspGetByColorAndCategory &#8216;Black&#8217;,'18&#8242;</h4>
<p>8) Stored procedures can return back multiple result sets. Create a new procedure with the following code.Hit execute</p>
<h4>CREATE PROCEDURE uspGetCustomersmultiple<br />
AS<br />
select * from SalesLT.Customer where CustomerID=21<br />
select * from SalesLT.Customer where CustomerID=22</h4>
<p>9) Execute the stored procedure by typing</p>
<h4>exec uspGetCustomersmultiple</h4>
<p>10) We can create a stored procedure using output parameters. In this example I need to retrieve a specific color and size scalar values for a given <strong>ProductID</strong> from the product table. So you can see the two variables that I declare and will use as output parameters. In this procedure I just pass in my output variables the values of <strong>Color</strong> and <strong>Size</strong> for the given <strong>ProductID</strong> which is the input parameter. So type the following statement in a query window and execute it.</p>
<h4>CREATE PROCEDURE uspProducts<br />
@ProductID int,<br />
@Color nvarchar(5) OUTPUT,<br />
@Size nvarchar(5) OUTPUT<br />
AS<br />
SELECT @Color = Color, @Size = Size<br />
FROM SalesLT.Product<br />
WHERE ProductID = @ProductID</h4>
<p>11) We must declare two new variables to receive the values of the two output parameters. Then we need to execute the stored procedure by passing it a <strong>productID</strong> of our choice. Finally we just output in the query window the two values which are the output parameters.Type the following statements and hit execute.</p>
<h4>DECLARE @myColor NVARCHAR(5)<br />
DECLARE @mySize NVARCHAR(5)<br />
exec uspProducts 680, @myColor OUT, @mySize OUT<br />
SELECT @myColor + &#8216; &#8211; &#8216; + @mySize AS ProductDetails</h4>
<p>That is all for now on this topic. For more info on stored procedures click <a href="http://msdn.microsoft.com/en-us/library/aa214299(SQL.80).aspx" target="_blank">here</a></p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/02/28/introduction-to-creating-modifying-executing-stored-procedures/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;h=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;Title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;title=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F28%2Fintroduction-to-creating-modifying-executing-stored-procedures%2F&amp;t=Introduction%20to%20creating%2C%20modifying%2C%20executing%20stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
Posted in Sql Server, Sql Server 2005, SQL Server 2008 Tagged: Sql Server 2005, SQL Server 2008, stored procedures <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/813/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=813&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/02/28/introduction-to-creating-modifying-executing-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Manipulating the HTML DOM of an asp.net page with Javascript</title>
		<link>http://dotnetstories.wordpress.com/2009/02/24/manipulating-the-html-dom-of-an-aspnet-page-with-javascript/</link>
		<comments>http://dotnetstories.wordpress.com/2009/02/24/manipulating-the-html-dom-of-an-aspnet-page-with-javascript/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 18:28:30 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=804</guid>
		<description><![CDATA[Manipulating the HTML DOM of an asp.net page with Javascript<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=804&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It has been a while, since I posted anything in my blog. It has been a very busy period for me. Hopefully I will get some time to write about Entity framework and ASP.NET Dynamic data. I will try to cover some of these new buzzwords in my next posts. I want to talk in this post about something that is relevant with the client side of things and more specifically the<a href="http://www.w3schools.com/htmldom/default.asp" target="_blank"> HTML DOM</a> and how we can manipulate it. I know that some of you might think that this blog is dedicated to the server side logic, based on the .Net platform. Yes that is true but when I feel I need to explain something regarding CSS,Javascript and XHTML, I will do so.</p>
<p>I had a seminar the past days and many people were asking how to manipulate various elements of an asp.net page with server side code. More specifically how to change the clickable text of a hyperlink (server side control), change the target link and make the link when clicked to open in a new window. You can do that with server side logic, using an asp.net language like C# or VB.Net. You must write the appropriate code in an event-handler routine, like button click event (we assume that there is also a button in the .aspx page) . Of course this triggers a post back to the server and all the logic is executed on the server. We do not want to do that, in this case.</p>
<p>The server does all the heavy lifting for us. We send along the wire an HTTP request and the server (in the case of an asp.net page) calls the asp.net engine and sends through an HTTP response back to the client pure XHTML, which the client can render easily.</p>
<p>There is no need for unecessary traffic back and forth from the server and the client. We want our application to be as responsive as possible and we can execute some of the logic above in the client.</p>
<p>In our scenario we can achieve what we want without sending an HTTP request back to the server. We can achieve this with Javascript and HTML DOM. All modern browsers know how to handle/interpert these technologies.</p>
<p>So we have in our asp.net page a hyperlink and a button. Originally the link points to the microsoft website, &#8220;http://www.microsoft.com&#8221;. The text of the link is &#8220;here&#8221; and when we click the button it shoud be changed to &#8220;Visit ASP.NET&#8221;</p>
<p>Also, when we click on the button we need to change the target of that link to the main ASP.Net site &#8220;http://www.asp.net&#8221;</p>
<p>1)Launch Visual Studio 2008/2005 or Visual Web developer express edition</p>
<p>2) Create an asp.net web site using the filesystem and C#. Name it &#8220;manipulatethedom&#8221;, or any other name you like it</p>
<p>3) You have an empty <strong>Default.aspx</strong> page. Just type the text &#8220;click here to navigate to our website&#8221; in the Design View. The word <strong>here</strong> will be our link in our example.</p>
<p>4) Drag and Drop an asp.net hyperlink server control on the page. Change the <strong>id</strong> attribute to &#8220;mylink&#8221;. Change the <strong>NavigateUrl</strong> attribute to &#8220;http://www.microsoft.com&#8221;</p>
<p>so your page should look like this now</p>
<h4>&lt;%@ Page Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221;  CodeFile=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;_Default&#8221; %&gt;</h4>
<h4>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</h4>
<h4>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</h4>
<h4>&lt;head runat=&#8221;server&#8221;&gt;</h4>
<h4>&lt;title&gt;&lt;/title</h4>
<h4>&lt;/head&gt;</h4>
<h4>&lt;body&gt;</h4>
<h4>&lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;</h4>
<h4>&lt;div&gt;</h4>
<h4>click</h4>
<h4>&lt;asp:HyperLink ID=&#8221;mylink&#8221; runat=&#8221;server&#8221;</h4>
<h4>NavigateUrl=&#8221;http://www.microsoft.com&#8221; style=&#8221;font-weight: 700&#8243;&gt;here&lt;/asp:HyperLink&gt; to navigate to our website</h4>
<h4>&lt;/div&gt;</h4>
<h4>&lt;/form&gt;</h4>
<h4>&lt;/body&gt;</h4>
<h4>&lt;/html&gt;</h4>
<p>5) Add an <strong>Html Button</strong> to the page. The <strong>onclick</strong> attribute should be &#8220;changelink()&#8221;. This is a javascript function that will be called when the user clicks the button. The <strong>value</strong> attribute could be &#8220;Change link&#8221;.</p>
<h4>&lt;input type=&#8221;button&#8221; onclick=&#8221;changelink()&#8221; value=&#8221;Change link&#8221; /&gt;</h4>
<p>6) Create an empty javascript file and call it <strong>changelink.js</strong>. You can do that by adding a new item, a .js file, in your website.</p>
<p>7) Create a link from your asp.net page to the external javascript file. This is the code and should be placed in the <strong>head</strong> section of the .aspx page.</p>
<h3>&lt;script src=&#8221;changelink.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</h3>
<p>8) The <strong>changelink.js</strong> file contents are</p>
<h3>function changelink()<br />
{</p>
<p>document.getElementById(&#8216;mylink&#8217;).innerHTML = &#8220;Visit ASP.NET&#8221;;<br />
document.getElementById(&#8216;mylink&#8217;).href = &#8220;http://www.asp.net&#8221;;<br />
document.getElementById(&#8216;mylink&#8217;).target = &#8220;_blank&#8221;;</p>
<p>}</h3>
<p>9) With VS 2008 there is built-in support for JavaScript Intellisense.  This is enabled in both the free Visual Web Developer 2008 Express edition as well as in Visual Studio, and makes using JavaScript significantly easier.</p>
<p>10 ) In this very simple file, I use the <strong>Document</strong> object which represents the entire HTML document and can be used to access all elements in a page.</p>
<p>11)  Then I use the <strong>getElementById()</strong> method which returns a reference to the first object with the specified      ID.Please remember that the value of the <strong>id</strong> attribute of my link in the asp.net page is &#8220;mylink&#8221;. So by typing</p>
<h3>document.getElementById(&#8216;mylink&#8217;),</h3>
<p>I get a reference of my link object on the page.</p>
<p>12) Then I use the <strong>innerHTML</strong> property which sets the text of the link to what I like.Similarly I use the <strong>href </strong>property sets the URL to the &#8220;http://www.asp.net&#8221;.Last, I use the<strong> target</strong> property to open the Url in a new window.</p>
<p>13) Run your application by hitting F5 and click on the button. Hopefully you will see all the changes that we have been discussing about.</p>
<p>So one must understand what kind of functionality can be achieved with client-side code and maybe shift the server side logic to the client.</p>
<p>Hope it helps!!! If you need any help, just email me.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2009/02/24/manipulating-the-html-dom-of-an-aspnet-page-with-javascript/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;h=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;Title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;title=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2009%2F02%2F24%2Fmanipulating-the-html-dom-of-an-aspnet-page-with-javascript%2F&amp;t=Manipulating%20the%20HTML%20DOM%20of%20an%20asp.net%20page%20with%20Javascript" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in asp.net, Javascript, XHTML Tagged: Javascript, XHTML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/804/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/804/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/804/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/804/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/804/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/804/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/804/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/804/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/804/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/804/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=804&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2009/02/24/manipulating-the-html-dom-of-an-aspnet-page-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ TO SQL and Stored procedures</title>
		<link>http://dotnetstories.wordpress.com/2008/12/13/linq-to-sql-and-stored-procedures/</link>
		<comments>http://dotnetstories.wordpress.com/2008/12/13/linq-to-sql-and-stored-procedures/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 16:17:23 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[c# 3.0]]></category>
		<category><![CDATA[.NET 3.5 Framework]]></category>
		<category><![CDATA[C#3.0]]></category>
		<category><![CDATA[Linq to Sql]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=782</guid>
		<description><![CDATA[In this post, I will go back to the issue of LINQ. I am going to show with an example how to use LINQ and stored procedures to insert,update and delete records from a particular table.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=782&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post, I will go back to the issue of LINQ. I am going to show with an example how to use LINQ and stored procedures to insert,update and delete records from a particular table.</p>
<p>I will use visual studio 2008 to create an asp.net application (c# version) that demonstrates how to use stored procs with LINQ.</p>
<p>If you want to see how LINQ treats stored procedures , have a look <a href="http://msdn.microsoft.com/en-us/library/bb386989.aspx" target="_blank">here</a></p>
<p>I am going to use the <strong>Pubs</strong> datatabase and in particular the <strong>Authors</strong> table.</p>
<p>I am pretty sure, because I have used the <strong>Pubs</strong> database in almost all my examples that you have installed it and attached it in your local instance of Sql Server.</p>
<p>You can use Visual Studio 2008 express edition and Sql Server express edition for this example.</p>
<p>We often need to use stored procs to talk with our database because there have many benefits</p>
<p>for example</p>
<ul>
<li> They allow modular programming.</li>
<li> They allow faster execution.</li>
<li> They can reduce network traffic.</li>
<li> They can be used as a security mechanism.</li>
</ul>
<p>First we need to create the 3 stored procedures that will insert,update and delete records from the <strong>Authors</strong> table</p>
<p>This is not a post on how to create stored procedures, so i am just going to paste here the complete stored procs.</p>
<ul>
<li>
<h3>DeleteAuthor</h3>
</li>
</ul>
<p><span style="color:#000000;"><em>USE [pubs]<br />
GO</em></span></p>
<p><em>SET ANSI_NULLS ON<br />
GO</em></p>
<p><em>SET QUOTED_IDENTIFIER ON<br />
GO</em></p>
<p><em>CREATE PROCEDURE [dbo].[DeleteAuthor]</em></p>
<p><em>@AuthorID nvarchar(20)</em></p>
<p><em>AS<br />
BEGIN</em></p>
<p><em>DELETE FROM authors<br />
WHERE au_id = @AuthorID</em></p>
<p><em>END<br />
GO<br />
</em></p>
<ul>
<li>
<h3>UpdateAuthor</h3>
</li>
</ul>
<p><span style="color:#999999;"><em>USE [pubs]<br />
GO</em></span></p>
<p><span style="color:#999999;"><em>SET ANSI_NULLS ON<br />
GO</em></span></p>
<p><span style="color:#999999;"><em>SET QUOTED_IDENTIFIER ON<br />
GO</em></span></p>
<p><span style="color:#999999;"><em>CREATE PROCEDURE [dbo].[UpdateAuthor]</em></span></p>
<p><span style="color:#999999;"><em>@authorID varchar(11),<br />
@lname nvarchar(50),<br />
@fname nvarchar(50),<br />
@phone char(12),<br />
@address nvarchar(40),<br />
@city nvarchar(40),<br />
@state char(2),<br />
@zip char(5),<br />
@contract bit</em></span></p>
<p><span style="color:#999999;"><em>AS<br />
BEGIN</em></span></p>
<p><span style="color:#999999;"><em>UPDATE authors<br />
SET</em></span></p>
<p><span style="color:#999999;"><em>au_lname=@lname,<br />
au_fname=@fname,<br />
phone=@phone,<br />
address=@address,<br />
city=@city,<br />
state=@state,<br />
zip=@zip,<br />
contract=@contract<br />
WHERE au_id  = @authorID</em></span></p>
<p><span style="color:#999999;"><em>END<br />
GO</em></span></p>
<ul>
<li>
<h3>InsertAuthor</h3>
</li>
</ul>
<p><em><span style="color:#999999;">USE [pubs]<br />
GO</span></em></p>
<p><em>SET ANSI_NULLS ON<br />
GO</em></p>
<p><em>SET QUOTED_IDENTIFIER ON<br />
GO</em></p>
<p><em>CREATE PROCEDURE [dbo].[InsertAuthor]<br />
@id varchar(11),<br />
@lName nvarchar(50),<br />
@fname nvarchar(50),<br />
@phone char(12),<br />
@address nvarchar(40),<br />
@city nvarchar(40),<br />
@state char(2),<br />
@zip char(5),<br />
@contract bit</em></p>
<p><em>AS<br />
BEGIN</em></p>
<p><em>INSERT INTO pubs.dbo.authors(<br />
au_id,<br />
au_lname,<br />
au_fname,<br />
phone,<br />
address,<br />
city,<br />
state,<br />
zip,<br />
contract)<br />
VALUES (<br />
@id,<br />
@lname,<br />
@fname,<br />
@phone,<br />
@address,<br />
@city,<br />
@state,<br />
@zip,<br />
@contract)</em></p>
<p><em>END</em></p>
<p><em>GO</em></p>
<p>1) Launch Visual Studio 2008</p>
<p>2) Create an ASP.net web application. Use C# a your language of development</p>
<p>3) Name your project &#8211; solution as you want.</p>
<p>4) Open the Server Explorer and connect to the Pubs database.</p>
<p>5) Add a new item in your project, a Linq to SQL classes, a .dbml file. name it authors.dbml</p>
<p>6) Drag and drop from the Server explorer window the <strong>authors</strong> table into the designer area (on the .dbml file)</p>
<p>7) Right-Click on the designer area and show the &#8220;Show methods Pane&#8221;</p>
<p>8) Drag and drop the stored procedures from the Server explorer to the designer area</p>
<p>9) Select the <strong>author</strong> entity from the deisgner area and select the Properties window. In the <strong>Default methods</strong> we need to assign the correct stored procs and not to leave the default option which is &#8220;use Runtime&#8221;. So please assign the different methods to their respective stored procs. Have a look at the picture below</p>
<p><a href="http://"></a><a href="http://dotnetstories.files.wordpress.com/2008/12/sql-linq.jpg"><img class="aligncenter size-full wp-image-783" title="sql-linq" src="http://dotnetstories.files.wordpress.com/2008/12/sql-linq.jpg?w=460&#038;h=287" alt="sql-linq" width="460" height="287" /></a></p>
<p>10) We will use these stored procs that are methods now as far as LINQ is concerned to update,insert and delete records from the database.</p>
<p>11) Add a button in the Default.aspx file. Name it &#8220;Update&#8221;.Double click on this button. In the event handling routine type:</p>
<h5><span style="color:#000000;"><em> using (authorsDataContext authdata = new authorsDataContext())</em></span></h5>
<h5><span style="color:#000000;"><em> {</em></span></h5>
<h5><span style="color:#000000;"><em> var author = (from a in authdata.authors</em></span></h5>
<h5><span style="color:#000000;"><em> where a.au_id == &#8220;238-95-7766&#8243;</em></span></h5>
<h5><span style="color:#000000;"><em> select a).Single();</em></span></h5>
<h5><span style="color:#000000;"><em> Response.Write(author.au_fname);</em></span></h5>
<h5><span style="color:#000000;"><em>author.au_fname = &#8220;nikolaos&#8221;;</em></p>
<h5>
<em>authdata.SubmitChanges();</em></h5>
<p></span></h5>
<h5><span style="color:#000000;"><em> }</em></span></h5>
<p>12) Add another button in the default.aspx page. Name it &#8220;After Update&#8221;.In this routine we try to see the updated value in the database.Double click on this button. In the event handling routine type:</p>
<h5>using (authorsDataContext authdata = new authorsDataContext())<br />
{<br />
var author = (from a in authdata.authors<br />
where a.au_id == &#8220;238-95-7766&#8243;<br />
select a).Single();<br />
</h5>
<h5>
Response.Write(author.au_fname);</h5>
<p>}<br />
12) Add another button in the default.aspx page and name it &#8220;Insert&#8221;.Double click on this button. In the event handling routine type:</p>
<h5>using (authorsDataContext authdata = new authorsDataContext())<br />
{</p>
<p>authdata.InsertAuthor(&#8220;216-49-8915&#8243;, &#8220;Jones&#8221;, &#8220;Michael&#8221;, &#8220;432423424&#8243;, &#8220;james street 123&#8243;, &#8220;New york&#8221;, &#8220;NY&#8221;, &#8220;94618&#8243;, true);<br />
</h5>
<h5>
authdata.SubmitChanges();<br />
}</h5>
<p>13) Add another button in the default.aspx page and name it &#8220;Delete&#8221;. Double click on this button. In the event handling routine type:</p>
<h5>using (authorsDataContext authdata = new authorsDataContext())<br />
{<br />
var author = (from a in authdata.authors<br />
where a.au_id == &#8220;216-49-8915&#8243;<br />
select a).Single();<br />
</h5>
<h5>
authdata.DeleteAuthor(author.au_id);<br />
</h5>
<h5>
authdata.SubmitChanges();<br />
}</h5>
<p>if you named you .dbml file &#8220;authors&#8221;, then there is a file &#8220;authors.designer.cs&#8221;. Inside there you will find this code</p>
<h5>private void Insertauthor(author obj)<br />
{<br />
this.InsertAuthor(default(string), default(string), default(string), obj.phone, obj.address, obj.city, obj.state, obj.zip, ((System.Nullable&lt;bool&gt;)(obj.contract)));<br />
}<br />
</h5>
<h5>
private void Updateauthor(author obj)<br />
{<br />
this.UpdateAuthor(obj.au_id, obj.au_lname, obj.au_fname, obj.phone, obj.address, obj.city, obj.state, obj.zip, ((System.Nullable&lt;bool&gt;)(obj.contract)));<br />
}<br />
</h5>
<h5>
private void Deleteauthor(author obj)<br />
{<br />
this.DeleteAuthor(default(string));<br />
}</h5>
<p>The methods above, are our stored procedures , which are called whenever we insert,update,delete</p>
<p>Hope it helps!!!</p>
<p>If you need the source code just email me.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/12/13/linq-to-sql-and-stored-procedures/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;h=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;Title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;title=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F13%2Flinq-to-sql-and-stored-procedures%2F&amp;t=LINQ%20TO%20SQL%20and%20Stored%20procedures" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" alt="Add to Furl" /></a></p>
Posted in c# 3.0, LINQ, SQL Server 2008, Visual Studio 2008 Tagged: .NET 3.5 Framework, C#3.0, Linq to Sql, Visual Studio 2008 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/782/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/782/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/782/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/782/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/782/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=782&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/12/13/linq-to-sql-and-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/12/sql-linq.jpg" medium="image">
			<media:title type="html">sql-linq</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Process Component to launch applications from our .Net application</title>
		<link>http://dotnetstories.wordpress.com/2008/12/03/using-the-process-component-to-launch-applications-from-our-net-project/</link>
		<comments>http://dotnetstories.wordpress.com/2008/12/03/using-the-process-component-to-launch-applications-from-our-net-project/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 21:11:52 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[VB 2005]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[process control]]></category>
		<category><![CDATA[windows forms]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=773</guid>
		<description><![CDATA[In this post I will show with a simple example how to use the Process control to launch applications from a windows form application (vb version). With this control that was shipped with the .Net 2.0 version you can launch very easily all sort of applications.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=773&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I will show with a simple example how to use the <strong>Process</strong> control to launch applications from a windows form application (vb version), with this control that was shipped with the .Net 2.0 version you can launch very easily all sort of applications.</p>
<p>Let&#8217;s get started then&#8230;</p>
<p>1) Launch Visual Studio 2008/2005-express editions will do</p>
<p>2) Create a windows form application. Choose VB as your development language.</p>
<p>3) Name your solution project with a name of your choice</p>
<p>4) Add 3 buttons on the form. Change the <strong>Text</strong> properties of the 3 button to &#8220;Launch Notepad&#8221;, &#8220;Launch Wordpad&#8221;, &#8220;Launch MS Paint&#8221;</p>
<p>5) Drag and Drop 3 <strong>Process</strong> controls from the ToolBox (Under  the Component tab) and name them &#8220;NotePadProcess&#8221;, &#8220;WordPadProcess&#8221;,&#8221;MSPaintProcess&#8221;</p>
<p>6) Add a reference to your project to the <strong>System.IO</strong> namespace from the Solutions explorer window, by right-clicking on your project name, then Properties, then Reference and select <strong>System.IO</strong> from the imported namespaces</p>
<p>7) Double Click on the button that is destined to launch Notepad. In the body of the routine type</p>
<h5>mypath = System.Environment.GetFolderPath(Environment.SpecialFolder.System)<br />
mypath = Path.Combine(mypath, &#8220;notepad.exe&#8221;)<br />
NotepadProcess.StartInfo.FileName = mypath<br />
NotepadProcess.Start()</h5>
<p>the code is pretty straight forward.We get to the notepad.exe file by finding the path and then we start notepad</p>
<p>8) Run your application, click on the &#8220;Notepad&#8221; button and see notepad launching</p>
<p>9) Double click on the two other buttons on the form designer. In their respective event handling routines type</p>
<p>for the button the launches <strong>wordpad</strong></p>
<h5>Dim mypath As String<br />
mypath = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)<br />
mypath = Path.Combine(mypath, &#8220;Windows NT\Accessories\wordpad.exe&#8221;)<br />
WordPadProcess.StartInfo.FileName = mypath<br />
WordPadProcess.Start()</h5>
<p>for the button the launches <strong>paint</strong></p>
<h5>Dim mypath As String<br />
mypath = System.Environment.GetFolderPath(Environment.SpecialFolder.System)<br />
mypath = Path.Combine(mypath, &#8220;mspaint.exe&#8221;)<br />
MSPaintProcess.StartInfo.FileName = mypath<br />
MSPaintProcess.Start()</h5>
<p>10) Run your application and then click on all the buttons</p>
<p>11) If you need to close all these applications programmatically you can add another 3 buttons on the form and (names:CloseNotepad,CloseWordpad,CloseMsPaint).Double click on the buttons and type respectively</p>
<h5>NotepadProcess.Kill()</h5>
<h5>WordPadProcess.Kill()</h5>
<h5>MSPaintProcess.Kill()</h5>
<p>12) Run your application. In order for this example to work, click once on the buttons to launch all 3 applications and then click on the &#8220;close&#8221; buttons to close the applications</p>
<p>13) If you try to close &#8220;Notepad&#8221; without first launching notepad you will receive an error.If you want to avoid that and close all the notepad instances you opened</p>
<p>instead of</p>
<h5>NotepadProcess.Kill()</h5>
<p>type in the body of the event handling routine</p>
<h5>Try</h5>
<h5>
Dim npProc() As Process<br />
</h5>
<h5>
npProc = Process.GetProcesses<br />
</h5>
<h5>
For Each proc As Process In npProc<br />
</h5>
<h5>
If proc.ProcessName.Equals(&#8220;notepad&#8221;) Then<br />
</h5>
<h5>
proc.Kill()<br />
</h5>
<h5>
End If<br />
</h5>
<h5>
Next<br />
</h5>
<h5>
Catch ex As Exception<br />
MessageBox.Show(ex.Message)<br />
End Try</h5>
<p>14) Do the same for the remaing two event handling routines that close MsPaint,WordPad</p>
<p>15) Now if you want to capture the moment that notepad closes, for any reason you need to add this line of  code</p>
<h5>NotepadProcess.EnableRaisingEvents = True</h5>
<p>in the button click event that launches <strong>Notepad</strong>.</p>
<p>So the complete code for the button that launches Notepad is</p>
<h5>Dim mypath As String</h5>
<h5>mypath = System.Environment.GetFolderPath(Environment.SpecialFolder.System)<br />
mypath = Path.Combine(mypath, &#8220;notepad.exe&#8221;)</h5>
<h5>NotepadProcess.EnableRaisingEvents = True</h5>
<h5>NotepadProcess.StartInfo.FileName = mypath<br />
NotepadProcess.Start()</h5>
<p>16)  Find the <strong>NotepadProcess</strong> (if you called it like that) process and choose the event <strong>Exited</strong> from the code window. The complete code is this</p>
<h5>Private Sub NotepadProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotepadProcess.Exited<br />
MessageBox.Show(&#8220;Notepad Exited&#8221;)<br />
End Sub</h5>
<p>17) Run your application. Launch <strong>Notepad</strong>. If you close <strong>Notepad</strong> by either clicking on the respective button on your form or just close <strong>Notepad</strong> from the close button, the code within this event will run</p>
<p>That is all folks!!!!</p>
<p>If you need the source code email me or leave a message.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/12/03/using-the-process-component-to-launch-applications-from-our-net-project/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;h=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;Title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;title=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F03%2Fusing-the-process-component-to-launch-applications-from-our-net-project%2F&amp;t=Using%20the%20Process%20Component%20to%20launch%20applications%20from%20our%20.Net%20application" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" alt="Add to Furl" /></a></p>
Posted in .NET, VB 2005, VB 9.0, Visual Studio 2005, Visual Studio 2008 Tagged: process control, Visual Studio 2005, Visual Studio 2008, windows forms <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/773/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=773&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/12/03/using-the-process-component-to-launch-applications-from-our-net-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Manage files,folders, special folders with VB.Net and window forms</title>
		<link>http://dotnetstories.wordpress.com/2008/12/01/manage-filesfolders-special-folders-with-vbnet-and-window-forms/</link>
		<comments>http://dotnetstories.wordpress.com/2008/12/01/manage-filesfolders-special-folders-with-vbnet-and-window-forms/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 20:09:03 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[VB 2005]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[general .net]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[folders]]></category>
		<category><![CDATA[System.IO]]></category>
		<category><![CDATA[windows forms]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=762</guid>
		<description><![CDATA[In this post I will show you how to implement file,folder related tasks, by merely using the classes and methods that are already written for us in the FCL in .Net and reside in the System.IO namespace.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=762&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hello all !!!</p>
<p>I came across a project today that it was required that we manage files,folders,special folders through windows forms.</p>
<p>Basically that specific functionality was already implemented with scripts. Some of the tasks required were implemented with <a title="WMI" href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" target="_blank">WMI</a> and some using the Windows Script Host <a href="http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx" target="_blank">FileSystemObject</a></p>
<p>If you want to find more scripts like that visit the <a href="\Acer\Empowering Technology" target="_blank">Script Center</a></p>
<p>In this post I will show you how to implement file,folder related tasks, by merely using the classes and methods that are already written for us in the FCL in .Net and reside in the <strong>System.IO</strong> namespace.</p>
<p>I will create an example so we can follow step by step how to accomplish a similar task</p>
<p>1) Launch Visual Studio 2005/2008.</p>
<p>2) Create a new Windows Forms project and choose VB as your development language.</p>
<p>3) Save your project-solution with a name of your choice.</p>
<p>4) Add a reference to the System.IO namespace from your project</p>
<p>5) Add a button and a listbox from the Toolbox on the form. Name the button &#8220;FindFiles&#8221;</p>
<p>6) In this first example we will see what methods to use to retrieve all files from a folder</p>
<p>7) Double click the button and in the event handling routine that is automatically created type this code</p>
<h5>Dim thefiles() As String<br />
&#8216;change the path to a path that exists in your machine<br />
thefiles = Directory.GetFiles(&#8220;C:\Acer\Empowering Technology&#8221;)</h5>
<h5>Me.ListBox1.DataSource = thefiles</h5>
<p>If you wanted to get files with a specific type e.g all .dll in tha folder you can replace this line</p>
<h5>thefiles = Directory.GetFiles(&#8220;C:\Acer\Empowering Technology&#8221;)</h5>
<p>with this</p>
<h5>thefiles = Directory.GetFiles(&#8220;C:\Acer\Empowering Technology&#8221;, &#8220;*.dll&#8221;)</h5>
<p>8)Build your solution and then run your application. Click on the button and see all the files from this particular folder to get listed inside the ListBox control. We use the <strong>Directory</strong> Class and the <strong>GetFiles</strong> method of this class.</p>
<p>9) Add another button in the for. Name it &#8220;FindFolders&#8221;. As you can imagine we will find all the subfolders inside that folder.Double click the button and in the event handling routine that is automatically created type this code</p>
<h5>Dim thefolders() As String</h5>
<h5>thefolders = Directory.GetDirectories(&#8220;C:\Acer\Empowering Technology&#8221;)</h5>
<h5>Me.ListBox1.DataSource = thefolders</h5>
<p>10) Run your application. Click on the &#8220;FindFolders&#8221; button and see all the subfolders from this particular folder to get listed inside the ListBox control</p>
<p>11) Let&#8217;s see now how we can access special folders like &#8220;My Pictures&#8221;, &#8220;My Documents&#8221;.Add another button in your form and name it &#8220;GetSpecialFolders&#8221;.We will try to get all the files inside the My Documents special folder.</p>
<p>12) Double click the button and in the event handling routine that is automatically created type this code</p>
<h5>Dim thefiles() As String</h5>
<h5>Dim specialfolder As String</h5>
<h5>specialfolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)</h5>
<h5>thefiles = Directory.GetFiles(specialfolder)</h5>
<h5>Me.ListBox1.DataSource = thefiles</h5>
<p>As you can see we use the <strong>Environment.SpecialFolder.MyDocuments</strong> toget access to that special folder.</p>
<p>13) In this final example I want to show you how to find information like file size for all the files that are inside the &#8220;C:\Acer\Empowering Technology&#8221; folder. We need to find the file size, the time the file was created and the extension of the file.</p>
<p>In order to to do that we must place 3 textboxes and 3 labels on our form. Change the text property of the first label to &#8220;FileSize&#8221; .Change the text property of the second label to &#8220;File Created&#8221; .Change the text property of the third label to &#8220;Extension&#8221;.</p>
<p>We will place the values we find for each file inside the textboxes.</p>
<p>We will use the <strong>SelectedIndexChanged</strong> event of the ListBox control to write our code. Just click on the Listbox control from the Form Designer. In the event routine that is created type the following lines.</p>
<h5>Dim theselectedfile As String</h5>
<h5>theselectedfile = Me.ListBox1.SelectedItem.ToString</h5>
<h5>Dim myfile As New FileInfo(theselectedfile)</h5>
<h5>Me.TextBox1.Text = myfile.Length.ToString()<br />
Me.TextBox2.Text = myfile.CreationTime.ToString()</h5>
<h5>Me.TextBox3.Text = myfile.Extension.ToString()</h5>
<p>14) Run your application and click on the button &#8220;FindFiles&#8221;. See the listbox populated with files. Just click on several files and see the results for each file inside the textboxes.</p>
<p>That is all folks!!! Hope it helps.Make sure you explore the other methods and classes in the System.IO namespace.</p>
<p>If you need the source code then you can email me or just leave a comment.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://Manage files,folders special folders with VB.Net and window forms" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;h=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;Title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;title=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2FManage%20files%2Cfolders%20special%20folders%20with%20VB.Net%20and%20window%20forms&amp;t=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F12%2F01%2Fmanage-filesfolders-special-folders-with-vbnet-and-window-forms%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in general .net, VB 2005, VB 9.0, Visual Studio 2005, Visual Studio 2008 Tagged: files, folders, System.IO, VB 2005, VB 9.0, windows forms <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/762/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/762/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/762/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/762/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/762/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/762/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/762/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/762/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/762/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/762/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=762&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/12/01/manage-filesfolders-special-folders-with-vbnet-and-window-forms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing from a windows form to microsoft word 2007 using VSTO</title>
		<link>http://dotnetstories.wordpress.com/2008/11/29/writing-from-a-windows-form-to-microsoft-word-2007-using-vsto/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/29/writing-from-a-windows-form-to-microsoft-word-2007-using-vsto/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 14:08:20 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[MS Office]]></category>
		<category><![CDATA[VB 2005]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[general .net]]></category>
		<category><![CDATA[VSTO]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=751</guid>
		<description><![CDATA[In this post I would like how easy it is to use Visual Studio Tools for Office. If you have never heard before of VSTO just google it. In a few words it is a component of Visual Studio(since Visual Studio 2005) that provides a robust, .NET-based environment for building business applications using classic Office programs like Word and Excel.  So that means you do not have to learn the specific Office object models, and of course you do need VBA anymore.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=751&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>First of all I want to thank all these people who read my posts and thank them for their encouraging comments.</p>
<p>In the feedack I receive I get some &#8220;complaints&#8221; that my posts are targeted towards the asp.net side of development. Well you are right. I am more knowledgeable in Asp.Net. But I promise to write more about windows forms in the future, starting from this post. And to all VB guys out there, i will try (starting from this post) to write more samples in VB, which is here to stay&#8230;</p>
<p>In this post I would like how easy it is to use <strong>Visual Studio Tools for Office</strong>. If you have never heard before of <strong>VSTO</strong> just google it. In a few words it is a component of Visual Studio(since Visual Studio 2005) that provides a robust, .NET-based environment for building business applications using classic Office programs like Word and Excel.  So that means you do not have to learn the specific Office object models, and of course you do not need VBA anymore.</p>
<p>Let&#8217;s show <strong>VSTO</strong> with a simple example. We will have a simple table(1 row and 3 cells) in a word 2007 (.docx) document and fill in the values of these 3 cells from a windows form.</p>
<p>1) Start Visual Studio 2008/2005 project.</p>
<p>2) From the &#8220;New Project&#8221; window  choose a Office 2007 and from the templates <strong>Word 2007 Document</strong>. Select <strong>VB</strong> as the development language.Give a name to your project and Press <strong>OK</strong></p>
<p>3) In the next window select &#8220;Create a new Document&#8221; and give name to your new word document, e.g &#8220;mydoc&#8221;.</p>
<p>4) Click &#8220;OK&#8221; to any window that asks you for access to the Office programs</p>
<p>5) If you have done everything right up to this point, you will be ablw to see in your visual studio window a blank word document,</p>
<p>6) Add a table with a single row and 3 cells from the ribbon</p>
<p>7) Add a new item in your project, a windows form and call it &#8220;wordform&#8221;</p>
<p>8) Add 3 Label controls on the form. Name them, <strong>Cell1,Cell2,Cell3</strong>.</p>
<p>9) Add 3 textbox controls on the form. Leave the default names</p>
<p>10) Add a button on the form. Leave the default name.</p>
<p>11) In the mydoc.vb(this is a file in my example-if you named your word, inputword, it will be inputword.vb) choose the Document.Open event. This is the empty routine.</p>
<h5>Private Sub ThisDocument_Open() Handles Me.Open</h5>
<h5>End Sub</h5>
<p>12) Inside this routine we need to show the form we created in the previous steps. So in the body of the routine, type</p>
<h5>Dim myform As New wordform()</h5>
<h5>myform.Show()</h5>
<p>13) Now we need to create a procedure (and place it in the same class file) to get the data from the form textboxes and place it in the respective cells. Type this code. It is really simple</p>
<h5>Public Sub writeintocells(ByVal cellinput As String, ByVal flag As Integer)<br />
Try</h5>
<h5>If flag = 1 Then<br />
Globals.ThisDocument.Tables(1).Rows(1).Cells(1).Range.Text = cellinput<br />
ElseIf flag = 2 Then<br />
Globals.ThisDocument.Tables(1).Rows(1).Cells(2).Range.Text = cellinput<br />
Else<br />
Globals.ThisDocument.Tables(1).Rows(1).Cells(3).Range.Text = cellinput<br />
End If<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message)<br />
End Try<br />
End Sub</h5>
<p>14) Go to your form. Double Click on the button.In the body event handling routine type</p>
<h5>If String.IsNullOrEmpty(TextBox1.Text) Then</h5>
<h5>MessageBox.Show(&#8220;enter a value&#8221;)</h5>
<h5>TextBox1.Focus()</h5>
<h5>Else</h5>
<h5>Globals.ThisDocument.writeintocells(Me.TextBox1.Text, 1)<br />
End If</h5>
<h5>If String.IsNullOrEmpty(TextBox2.Text) Then</h5>
<h5>MessageBox.Show(&#8220;enter a value&#8221;)</h5>
<h5>TextBox2.Focus()</h5>
<h5>Else</h5>
<h5>Globals.ThisDocument.writeintocells(Me.TextBox2.Text, 2)<br />
End If</h5>
<h5>If String.IsNullOrEmpty(TextBox3.Text) Then</h5>
<h5>MessageBox.Show(&#8220;enter a value&#8221;)</h5>
<h5>TextBox3.Focus()<br />
Else</h5>
<h5>Globals.ThisDocument.writeintocells(Me.TextBox3.Text, 3)<br />
End If</h5>
<p>In this routine we access our document and access the procedure that we created in our document. We pass the values from the textboxes to the procedure and the procedure writes these values in the cells in the word document</p>
<p>15)Add another button on your form. Leave the default name. Double Click the button and in the body of the event handling routine type</p>
<h5>Globals.ThisDocument.Save()<br />
Globals.ThisDocument.Close()</h5>
<p>In this routine we just save and close the document.</p>
<p>16) Build and run your project. Type 3 values in the textboxes in your form and bress <strong>Button1</strong>.</p>
<p>See the values inserted in the cells. Click <strong>Button2</strong> to save and close the document.</p>
<p>Hopefully everything makes sense&#8230;</p>
<p>If you need the source code just email me or leave a comment!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/29/writing-from-a-windows-form-to-microsoft-word-2007-using-vsto/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;h=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;Title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;title=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F29%2Fwriting-from-a-windows-form-to-microsoft-word-2007-using-vsto%2F&amp;t=Writing%20from%20a%20windows%20form%20to%20microsoft%20word%202007%20using%20VSTO" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in general .net, MS Office, VB 2005, VB 9.0, Visual Studio 2005, Visual Studio 2008 Tagged: VB 2005, Visual Studio 2005, Visual Studio 2008, VSTO <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/751/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/751/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/751/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=751&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/29/writing-from-a-windows-form-to-microsoft-word-2007-using-vsto/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with DAL (data access layer), BLL(Business Logic Layer) in asp.net web applications</title>
		<link>http://dotnetstories.wordpress.com/2008/11/26/working-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/26/working-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 22:14:17 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2005]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net 2.0]]></category>
		<category><![CDATA[BLL]]></category>
		<category><![CDATA[Business Logic Layer]]></category>
		<category><![CDATA[DAL]]></category>
		<category><![CDATA[Data Acccess Layer]]></category>
		<category><![CDATA[Presentation Layer]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=703</guid>
		<description><![CDATA[Creating a data access layer(DAL) and a business logic layer(BLL) for a simple asp.net web application<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=703&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I would like to show you step by step how to create a <a href="http://en.wikipedia.org/wiki/Data_access_layer" target="_blank">DAL</a> and <a href="http://en.wikipedia.org/wiki/Business_layer" target="_blank">BLL</a> for an ASP.NET web application.</p>
<p>Well, DAL stands for <strong>Data Access Layer</strong> and BLL, stands for <strong>Business Logic Layer</strong>.</p>
<p>We will use strongly <strong>Typed DataSets</strong> to create the DAL and class files to implement the BLL, which enforces the business rules of our application.</p>
<p>Many developers get puzzled when they come across these terms. I will try to explain these concepts to the best of my ability and I will show how easy is to implement these sort of layers with the tools we have in our disposal. I will also try to explain why we need to implement these layers when we develop a n-tier project that accesses a database.</p>
<p>The most common thing in web/windows development is to store data in a database. We write code to save the data in the database and write code to manipulate the data e.g to insert, update,delete data in the database.</p>
<p>Obviously for this example we will need a database. I will use the <strong>Pubs</strong> database. This is a well known database and many people are familiar with its schema.</p>
<p>In order to follow this example you need to download this database and attach it in your local instance of the SQL Server. You can download the <strong>Pubs</strong> database from this <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46a0-8da2-eebc53a68034&amp;DisplayLang=en" target="_blank">link</a>.</p>
<p>If you need some help on how to install the database have a look <a href="http://www.codeproject.com/KB/database/InstallingNorthwindAndPub.aspx" target="_blank">here</a></p>
<p>You can download Visual Studio 2008 from <a href="http://www.microsoft.com/express/vwd/" target="_blank">here</a> and SQL Server 2008 Express from this <a href="http://www.microsoft.com/express/sql/register/" target="_blank">link. </a></p>
<p>It is for free!!! So I assume that by this point you have all the tools downloaded and installed. At this point you must have the Pubs database in the local instance of your SQL Server.</p>
<p>We will create the DAL first. But why we need a DAL? It is not a good idea-strategy (especially if we deal with a big-complex application) to have the data-specific logic put into the presentation layer.So it is wrong to write the ADO.NET code in the .aspx pages of our application. All the data related code should be in the DAL. From the presentation layer we should only make calls to the DAL for all data requests.</p>
<p>Let&#8217;s get started then&#8230;</p>
<p>1) Fire up Visual studio 2008/2005</p>
<p>2) Create a new ASP.Net web application using C# as the development language</p>
<p>3) Name your project as you wish</p>
<p>4) Go to the <strong>Server Explorer</strong> in Visual Studio, right-click on the <strong>Data Connections</strong> node, and choose <strong>Add Connection</strong>. This will bring up the <strong>Add Connection</strong> dialog box, where you can specify the server to connect to, the authentication information, and the database name.Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/addconnection.jpg"><img class="aligncenter size-full wp-image-707" title="addconnection" src="http://dotnetstories.files.wordpress.com/2008/11/addconnection.jpg?w=460&#038;h=287" alt="addconnection" width="460" height="287" /></a></p>
<p>Click the OK button. After configuring the database,  the database will be added as a node underneath the <strong>Data Connections</strong> node. You can expand the node to explore its tables, views, stored procedures of the database.</p>
<p>5) We must add a <a href="http://msdn.microsoft.com/en-us/library/esbykkzb(VS.71).aspx" target="_blank">Typed DataSet</a> to our project. To do this, right-click on the project node in the Solution Explorer and choose <strong>Add a New Item</strong>. Select the <strong>DataSet</strong> option from the list of templates and name it <strong class="action">Pubs.xsd</strong>.</p>
<p>See the  picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/add-dataset.jpg"><img class="aligncenter size-full wp-image-709" title="add-dataset" src="http://dotnetstories.files.wordpress.com/2008/11/add-dataset.jpg?w=460&#038;h=287" alt="add-dataset" width="460" height="287" /></a></p>
<p><strong>Typed DataSets</strong> are a set of generated classes (generated by Visual Studio) that inherit directly from the <strong>DataSet </strong>family of classes.The members of these classes are strongly-typed according to the database schema.</p>
<p>A <strong>Typed DataSet</strong> is composed of strongly-typed <strong>DataTable</strong> instances which represents any of the underlying database tables. We need to create a DataTable for the <strong class="action">Authors</strong> table. Besides having our table properties as objects inside the <strong>DataTable</strong> object we need to use the <strong>TableAdapter</strong> class so we can have the necessary methods to access the data from the table.</p>
<p>6) Navigate to the <strong class="action">Pubs.xsd,</strong><span class="action"> drag and drop a <strong>TableAdapter class. </strong>The configuration wizard fires up.</span></p>
<p><span class="action">See the picture below</span></p>
<p><span class="action"><a href="http://dotnetstories.files.wordpress.com/2008/11/wizard-1.jpg"><img class="aligncenter size-full wp-image-712" title="wizard-1" src="http://dotnetstories.files.wordpress.com/2008/11/wizard-1.jpg?w=460&#038;h=287" alt="wizard-1" width="460" height="287" /></a></span></p>
<p><span class="action">7) Save the connection string to the <strong>web.config</strong> as suggested.</span></p>
<p><span class="action">8) Click <strong>Next</strong>. Have a look at the picture below</span></p>
<p><span class="action"><a href="http://dotnetstories.files.wordpress.com/2008/11/wizard-21.jpg"><img class="aligncenter size-full wp-image-714" title="wizard-21" src="http://dotnetstories.files.wordpress.com/2008/11/wizard-21.jpg?w=460&#038;h=287" alt="wizard-21" width="460" height="287" /></a></span></p>
<p><span class="action">In this step<strong> </strong>we define the query(using the first option-ad hod sql queries)</span> that returns the columns from the table <strong>Authors</strong> that we want reflected in our DataTable. At the end of the wizard we&#8217;ll give a method name to this query.We will use this method to populate the strongly-typed DataSet.</p>
<p>9) Click <strong>Next</strong> and then from the <strong>Query Builder</strong> select the <strong>Authors</strong> table and click <strong>Add</strong>. We use the <strong>Query Builder</strong> to graphically construct the query. You must select all the fields from the <strong>Authors</strong> table. Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/wizard-32.jpg"><img class="aligncenter size-full wp-image-717" title="wizard-32" src="http://dotnetstories.files.wordpress.com/2008/11/wizard-32.jpg?w=460&#038;h=287" alt="wizard-32" width="460" height="287" /></a></p>
<p><span class="action">10) Click <strong>Next. </strong>Have a look at the picture below </span></p>
<p><span class="action"><a href="http://dotnetstories.files.wordpress.com/2008/11/wizard-4.jpg"><img class="aligncenter size-full wp-image-719" title="wizard-4" src="http://dotnetstories.files.wordpress.com/2008/11/wizard-4.jpg?w=460&#038;h=287" alt="wizard-4" width="460" height="287" /></a><br />
</span></p>
<p><span class="action">Rename the </span><strong>Return a DataTable section </strong>from <strong>GetData</strong> to <strong>GetAuthors</strong>.</p>
<p>We will use this method from our presentation layer to create and fill the <strong>DataTable</strong> and return it.</p>
<p>11) Click <strong>Next</strong> and then <strong>Finish</strong>. The wizard closed. If we go to the <strong>DataSet Designer</strong> we can see</p>
<ul>
<li>The DataTable we just created, <strong class="action">Pubs.authorsDataTable</strong></li>
<li>The <strong class="action">PubsTableAdapters.AuthorsTableAdapter </strong>and the methods (<strong class="action">Fill()</strong> and <strong class="action">GetAuthors()</strong>)</li>
</ul>
<p>See the picture below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/dataset-designer.jpg"><img class="aligncenter size-full wp-image-720" title="dataset-designer" src="http://dotnetstories.files.wordpress.com/2008/11/dataset-designer.jpg?w=460&#038;h=287" alt="dataset-designer" width="460" height="287" /></a></p>
<p>12) Switch to the <strong>Default.aspx</strong> and in the <strong>Page_Load</strong> event type the following lines of code.</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();</h5>
<h5>Pubs.authorsDataTable myauthors;</h5>
<h5>myauthors = myadapter.GetAuthors();</h5>
<h5>foreach(Pubs.authorsRow authorrow in myauthors)</h5>
<h5>Response.Write(&#8220;Author: &#8221; + authorrow.au_fname + &#8220;  &#8221; + authorrow.au_lname+  &#8220;&lt;br /&gt;&#8221;);</h5>
<p>13) As you can see in the first line we create an instance of our <strong>authorsTableAdapter</strong>.</p>
<p>Run your application and you will see all the authors.</p>
<p>14) Now we can bind the objects (data) contained in the <strong>DataTable </strong>to a Gridview web server control.Add a new page by adding a new item  in your project.Name it <strong>GridviewDataTable.aspx</strong>.Set this page as <strong>Start Page</strong>.</p>
<p>15) Drag and Drop a <strong>Gridview</strong> control on the page. Leave the default name.</p>
<p>In the <strong>Page_Load</strong> event of this page type the following code</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();</h5>
<h5>GridView1.DataSource = myadapter.GetAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>Run your application and you will see the results returned by the <strong>Authors</strong> table through the <strong>DataTable</strong> object in the <strong>GridView</strong>.</p>
<p>16) We need to select a specific row from the table <strong>Authors</strong>. In order to achieve that we need to create a new method that takes an argument. To create such a method, switch to the DataSet Designer and add a new query. Have a look at the picture below.</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/addquery.jpg"><img class="aligncenter size-full wp-image-722" title="addquery" src="http://dotnetstories.files.wordpress.com/2008/11/addquery.jpg?w=460&#038;h=287" alt="addquery" width="460" height="287" /></a></p>
<p>17) Click <strong>Next</strong> (Leave the first option selected). Click Next again, (Leave the first option selected)</p>
<p>18) Click <strong>Next</strong> in the wizard and add the following SQL statement</p>
<h5>SELECT        au_id, au_lname, au_fname, phone, address, city, state, zip, contract<br />
FROM            authors<br />
where au_id=@au_id</h5>
<p>Have a look at the picture below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/sql.jpg"><img class="aligncenter size-full wp-image-724" title="sql" src="http://dotnetstories.files.wordpress.com/2008/11/sql.jpg?w=460&#038;h=287" alt="sql" width="460" height="287" /></a></p>
<p>19) Click <strong>Next</strong>. In the <strong>Return a</strong> <strong>DataTable</strong>, change the name to <strong>GetAuthorByID</strong> and then click <strong>Finish.</strong></p>
<p>20) In the DataSet Designer you will see the new method we just created.</p>
<p>21) Right-Click on this new method (<strong>GetAuthorByID</strong>) and select <strong>Preview Data. </strong>In the Preview Data windows type this &#8220;172-32-1176&#8243; in the <em>Value</em> fields in the <em>Parameters</em> section. Click <em>Preview</em>.</p>
<p>22) Add a new page to your project. Call it <strong>GetAuthorsbyid.aspx</strong>.Set it as the <strong>Start Page</strong></p>
<p>23) Run your application. In the web page you should see the following result</p>
<table id="GridView1" style="border-collapse:collapse;height:16px;" border="1" cellspacing="0" width="598" rules="all">
<tbody>
<tr>
<td>172-32-1176</td>
<td>White</td>
<td>Johnson</td>
<td>408 496-7223</td>
<td>10932 Bigge Rd.</td>
<td>Menlo Park</td>
<td>CA</td>
<td>94025</td>
</tr>
</tbody>
</table>
<p>24) Obviously we want to insert,update,delete rows in the table. We can do that by using the <strong class="action">Insert()</strong>, <strong class="action">Update()</strong>, and <strong class="action">Delete()</strong> methods of our <strong>TableAdapter</strong> class that are already created for us.</p>
<p>Have a look at the image below</p>
<p><a href="http://dotnetstories.files.wordpress.com/2008/11/dataset-methods.jpg"><img class="aligncenter size-full wp-image-728" title="dataset-methods" src="http://dotnetstories.files.wordpress.com/2008/11/dataset-methods.jpg?w=460&#038;h=287" alt="dataset-methods" width="460" height="287" /></a></p>
<p>25) To insert a new row in the Authors table, we switch to the <strong>GridviewDataTable.aspx</strong> (make it as a Start Page) and place a button on the page. Change the text property of the button to &#8220;Insert&#8221; (There is already a gridview in this page). Double click on the button and in the event handler routine type,</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();</h5>
<h5>myadapter.Insert(&#8220;122-33-5667&#8243;, &#8220;Austen&#8221;, &#8220;Jane&#8221;, &#8220;33216321737&#8243;, &#8220;12 london street&#8221;, &#8220;London&#8221;, &#8220;SO&#8221;, &#8220;99029&#8243;, false);</h5>
<h5>GridView1.DataSource = myadapter.GetAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>Run your application and see the new row is inserted in the gridview and thus in the underlying table</p>
<p>26) Let&#8217;s try to update the record we just inserted. Just add a new button on the page. Change the text property of the button to &#8220;Update&#8221;. Double click on the button and in the event handler routine type,</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();</h5>
<h5>myadapter.Update(&#8220;122-33-5667&#8243;, &#8220;Austen&#8221;, &#8220;Jane&#8221;, &#8220;33216321737&#8243;, &#8220;22 london street&#8221;, &#8220;London&#8221;, &#8220;SO&#8221;, &#8220;99029&#8243;, false, &#8220;122-33-5667&#8243;);</h5>
<h5>GridView1.DataSource = myadapter.GetAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>Run your application and see the row updated in the gridview and thus in the underlying table</p>
<p>27) Finally we will try to delete the row we inserted and updated in the previous steps.Just add a new button on the page. Change the text property of the button to &#8220;Delete&#8221;. Double click on the button and in the event handler routine type,</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();myadapter.Delete(&#8220;122-33-5667&#8243;);<br />
GridView1.DataSource = myadapter.GetAuthors();<br />
GridView1.DataBind();</h5>
<p>Run your application and see the row is deleted in the gridview and thus in the underlying table.</p>
<p>28) Now we will try to create a new functionality that does a mass update and not just updating a row like the previous example. We will implement the following scenario, for every author that lives in California (state=&#8221;CA&#8221; ) his contract will be valid (contract=true). Just add a new button on the page. Change the text property of the button to &#8220;Update multiple&#8221;. Double click on the button and in the event handler routine type,</p>
<h5>PubsTableAdapters.authorsTableAdapter myadapter = new PubsTableAdapters.authorsTableAdapter();</h5>
<h5>Pubs.authorsDataTable myauthors;</h5>
<h5>myauthors = myadapter.GetAuthors();</h5>
<h5>foreach (Pubs.authorsRow author in myauthors)</h5>
<h5>if (author.state == &#8220;CA&#8221;)</h5>
<h5>author.contract = true;</h5>
<h5>myadapter.Update(myauthors);</h5>
<h5>GridView1.DataSource = myadapter.GetAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>29) Now I would like to move on and talk a bit about the BLL. We have covered enough on how to seperate the data access logic from the presentation logic.If we want to have certain business rules that define who is given the authority to do ( e.g delete,update authors) or that for certain states special discounts should be applied, a Business Logic Layer (BLL) that serves as an intermediary for data exchange between the presentation layer and the DAL must be implemented. I will implement the BLL as a  class file because we have one TableAdapter in the DAL. Inside this class we will have methods that map to the data access methods in the DAL.</p>
<p>30 ) Simply right-click in the Solution Explorer and then Add a New Item, and choose the Class template. Name the class <strong>BLLAuthors</strong>.<strong>cs</strong>. The first method we will create, is simply a wrapper method for the method <strong>GetAuthors()</strong> in the DAL and we will call it <strong>GetBLLAuthors()</strong>. We will create a second method which we will call <strong>GetBLLAuthorsByID</strong>. This method is still a wrapper method for the <strong>GetAuthorsByID </strong>in the DAL. In this first example I want to show you how to access the typed datasets of the DAL through BLL. We will see later, methods in the BLL that enforce business rules(which is the point of having a BLL). The code inside the<strong> BLLAuthors</strong>.<strong>cs </strong>is as following</p>
<h5>using System;</h5>
<h5>using System.Collections.Generic;</h5>
<h5>using System.Linq;</h5>
<h5>using System.Web;</h5>
<h5>using DAL_BLL.PubsTableAdapters;</h5>
<h5>[System.ComponentModel.DataObject]</h5>
<h5>public class BLLAuthors</h5>
<h5>{</h5>
<h5>private authorsTableAdapter myAdapter = null;</h5>
<h5>protected authorsTableAdapter Adapter</h5>
<h5>{</h5>
<h5>get {</h5>
<h5>if (myAdapter == null) myAdapter = new authorsTableAdapter();</h5>
<h5>return myAdapter;</h5>
<h5>}</h5>
<h5>}</h5>
<h5>[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]</h5>
<h5>public DAL_BLL.Pubs.authorsDataTable GetBLLAuthors()</h5>
<h5>{</h5>
<h5>return Adapter.GetAuthors();</h5>
<h5>}</h5>
<h5>[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]</h5>
<h5>public DAL_BLL.Pubs.authorsDataTable GetBLLAuthorsByID(string authorid)</h5>
<h5>{</h5>
<h5>return Adapter.GetAuthorByID(authorid);</h5>
<h5>}</h5>
<h5>}</h5>
<p>31) Create a new web page and name it <strong>GridviewBLL.aspx</strong>. Set this page as the <strong>Start Page.</strong></p>
<p>Add a Gridview control on the page. In the <strong>Page_Load</strong> event of this page type,</p>
<h5>BLLAuthors authorsall = new BLLAuthors();</h5>
<h5>GridView1.DataSource = authorsall.GetBLLAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>As you can see in the first line we create an instance of our <strong>BLLAuthors</strong> class which we defined in our <strong>BLLAuthors</strong>.<strong>cs </strong>file. It is evident from the code above that from the presentation layer (.aspx page) we access the BLL and then the BLL accesses the DAL, which eventually  &#8220;talks&#8221; to the database.</p>
<p>32) Let&#8217;s see a little example of our second wrapper method in our BLL. Add a button control to the page.Change the text property of the to &#8220;SelectSingleAuthor&#8221;. Double click the button. In the event handling routine type,</p>
<h5>BLLAuthors singleauthor = new BLLAuthors();<br />
GridView1.DataSource = singleauthor.GetBLLAuthorsByID(&#8220;172-32-1176&#8243;);<br />
GridView1.DataBind();</h5>
<p>Run your application. In the web page you should see the following result</p>
<table id="GridView1" style="border-collapse:collapse;height:16px;" border="1" cellspacing="0" width="598" rules="all">
<tbody>
<tr>
<td>172-32-1176</td>
<td>White</td>
<td>Johnson</td>
<td>408 496-7223</td>
<td>10932 Bigge Rd.</td>
<td>Menlo Park</td>
<td>CA</td>
<td>94025</td>
</tr>
</tbody>
</table>
<p>33) Let&#8217;s create a third method that applies this business rule (we used the same example in the DAL section),if  the state of the author is California &#8220;<strong>CA</strong>&#8221; then the contract should be true.</p>
<p>The code you should put in the <strong>BLLAuthors.cs </strong>is this</p>
<h5>public bool UpdateAuthor()</h5>
<h5>{</h5>
<h5>DAL_BLL.Pubs.authorsDataTable authors = Adapter.GetAuthors();</h5>
<h5>if (authors.Count == 0)</h5>
<h5>return false;</h5>
<h5>foreach (DAL_BLL.Pubs.authorsRow authorrow in authors)</h5>
<h5>if (authorrow.state == &#8220;CA&#8221;)</h5>
<h5>authorrow.contract = true;</h5>
<h5>// Update the author record</h5>
<h5>int rowsAffected = Adapter.Update(authors);</h5>
<h5>return rowsAffected == 1;</h5>
<h5>}</h5>
<p>Add a button control to the page.Change the text property of the to &#8220;UpDateState&#8221;. Double click the button. In the event handling routine type,</p>
<h5>BLLAuthors upauthor = new BLLAuthors();<br />
upauthor.UpdateAuthor();</h5>
<h5>GridView1.DataSource=upauthor.GetBLLAuthors();</h5>
<h5>GridView1.DataBind();</h5>
<p>Run your application. In the web page you should see all records with state=&#8221;<strong>CA</strong>&#8221; to have the contract=&#8221;<strong>True</strong>&#8220;</p>
<p>You could insert the code above in a Try-Catch Statement&#8230;.</p>
<h5>try<br />
{<br />
BLLAuthors upauthor = new BLLAuthors();upauthor.UpdateAuthor();<br />
</h5>
<h5>
GridView1.DataSource = upauthor.GetBLLAuthors();<br />
GridView1.DataBind();<br />
}<br />
catch (ArgumentException te)<br />
</h5>
<h5>
{<br />
Response.Write(&#8220;problem: &#8221; + te.Message);<br />
}</h5>
<p>Hope it helps and happy coding!!!</p>
<p>If you need the source code feel free to email me. You can find my email in this <a href="http://dotnetstories.wordpress.com/about/" target="_blank">page</a></p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/26/working-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;h=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;Title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;title=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F26%2Fworking-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications%2F&amp;t=Working%20with%20DAL%20(data%20access%20layer)%2C%20BLL(Business%20Logic%20Layer)%20in%20asp.net%20web%20applications" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" alt="Add to Furl" /></a></p>
<a name="pd_a_1139394"></a><div class="PDS_Poll" id="PDI_container1139394" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1139394.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1139394/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://www.polldaddy.com">survey software</a></span>
		</noscript>
Posted in asp.net 2.0, C#, Sql Server, Sql Server 2005, SQL Server 2008, Visual Studio 2005, Visual Studio 2008 Tagged: asp.net 2.0, BLL, Business Logic Layer, C#, DAL, Data Acccess Layer, Presentation Layer, Visual Studio 2005, Visual Studio 2008 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/703/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/703/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/703/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/703/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/703/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/703/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/703/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/703/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/703/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/703/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=703&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/26/working-with-dal-data-access-layer-bllbusiness-logic-layer-in-aspnet-web-applications/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/addconnection.jpg" medium="image">
			<media:title type="html">addconnection</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/add-dataset.jpg" medium="image">
			<media:title type="html">add-dataset</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/wizard-1.jpg" medium="image">
			<media:title type="html">wizard-1</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/wizard-21.jpg" medium="image">
			<media:title type="html">wizard-21</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/wizard-32.jpg" medium="image">
			<media:title type="html">wizard-32</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/wizard-4.jpg" medium="image">
			<media:title type="html">wizard-4</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/dataset-designer.jpg" medium="image">
			<media:title type="html">dataset-designer</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/addquery.jpg" medium="image">
			<media:title type="html">addquery</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/sql.jpg" medium="image">
			<media:title type="html">sql</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/dataset-methods.jpg" medium="image">
			<media:title type="html">dataset-methods</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the FileUpload web server control in your asp.net website</title>
		<link>http://dotnetstories.wordpress.com/2008/11/22/using-the-fileupload-web-server-control-in-your-aspnet-website/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/22/using-the-fileupload-web-server-control-in-your-aspnet-website/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 15:44:43 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[asp.net 2.0]]></category>
		<category><![CDATA[FileUpload control]]></category>
		<category><![CDATA[web server controls]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=684</guid>
		<description><![CDATA[I will try to demonstrate,as always with an example, how to upload one file and how to upload multiple files using the FileUpload control<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=684&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post i would like to talk about another web server control, <strong>FileUpload</strong>, which was a control included in  the ASP.Net 2.0 framework. I will try to demonstrate,as always with an example, how to upload one file and how to upload multiple files using the <strong>FileUpload</strong> control. Basically with this control you try to give the user the same functionailty with a ftp client.</p>
<p>For more information on this control have a look at the msdn reference, <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload(VS.80).aspx" target="_blank">here</a></p>
<p>If you remember back in the days of ASP.NET 1.0 and ASP.NET 1.1 we had to use  the HTML FileUpload server control. This control put an <code>&lt;input type="file"&gt;</code> element on your Web page to enable the end user to upload files to the server. To make this work however, we had to add, <code>enctype="multipart/form-data"</code> to the page&#8217;s <code>&lt;form&gt;</code> element.</p>
<p>Let&#8217;s start a new project to demonstrate out example</p>
<p>1) Launch Visual Studio 2005/2008</p>
<p>2) Create a new asp.net web application in C#</p>
<p>3) Call it &#8220;uploadcontrol&#8221;</p>
<p>4) Drag and drop in the <em>default.aspx</em> page a <strong>FileUpload </strong>control from the Toolbox</p>
<p>5) If you run your application now , you will see a page that does not do much, just a textbox and &#8220;Browse&#8221; button that are part of the FileUpload control</p>
<p>6) Stop your application and place a button in the <em>default.aspx </em>page</p>
<p>7) Add a Label control in your application. Leave the default names for all the controls on the page.</p>
<p>8) Create a folder in the C drive and call it &#8220;myUploads&#8221;</p>
<p>9) Double click on the button and in the event handling routine and type</p>
<h4>if (FileUpload1.HasFile) {<br />
FileUpload1.SaveAs(&#8220;C:\\myUploads\\&#8221; + FileUpload1.FileName);<br />
Label1.Text = &#8220;File name: &#8221; +<br />
FileUpload1.PostedFile.FileName + &#8220;&lt;br&gt;&#8221; +<br />
FileUpload1.PostedFile.ContentLength + &#8221; kb&lt;br&gt;&#8221; +<br />
&#8220;Content type: &#8221; +<br />
FileUpload1.PostedFile.ContentType;<br />
}<br />
else<br />
{<br />
Label1.Text = &#8220;You have not selected a file or the file has not been found.&#8221;;<br />
}</h4>
<p>First of all let&#8217;s explain the lines above.</p>
<p>Initially we use the <strong>HasFile</strong> Property which returns a value indicating whether the <strong><span>FileUpload</span></strong> control contains a file.</p>
<p>10) Run your application again and try to upload a file</p>
<p>If that is true we append in the text property of the Label control , the following information</p>
<ul>
<li>filename</li>
<li>file size</li>
<li>type of the document, e.g image,word document, e.t.c</li>
</ul>
<p>We achieve that by using the <strong>PostedFile</strong> property , which holds the file that is being uploaded.</p>
<p>Before going to show more things regarding the FileUpload control, i will add a <strong>Try Catch</strong> statement in the code above to provide some sort of exception handling.</p>
<h4>if (FileUpload1.HasFile)<br />
try<br />
{<br />
FileUpload1.SaveAs(&#8220;C:\\myUploads\\&#8221; + FileUpload1.FileName);<br />
Label1.Text = &#8220;File name: &#8221; +<br />
FileUpload1.PostedFile.FileName + &#8220;&lt;br&gt;&#8221; +<br />
FileUpload1.PostedFile.ContentLength + &#8221; kb&lt;br&gt;&#8221; +<br />
&#8220;Content type: &#8221; +<br />
FileUpload1.PostedFile.ContentType;<br />
}<br />
catch (Exception ex)<br />
{<br />
Label1.Text = &#8220;ERROR: &#8221; + ex.Message.ToString();<br />
}<br />
else<br />
{<br />
Label1.Text = &#8220;You have not specified a file or the file has not been found.&#8221;;<br />
}</h4>
<p>Now let&#8217;s see how you can upload mutliple files from a single page.</p>
<p>1) Create a new .aspx page and add it to your project, by adding a new item from the Solutions window.</p>
<p>2) Place 3 <strong>FileUpload</strong> controls on the page. Also add a button and a label control.</p>
<p>3) double click on the button</p>
<p>4) In the event handling routine for the click event of the button, type</p>
<h4>thefileupload(FileUpload1);<br />
thefileupload(FileUpload2);<br />
thefileupload(FileUpload3);</h4>
<p>In order to upload the three files at once, I make 3 seperate calls to the method , <strong>thefileupload.</strong></p>
<p>So I have created a method of my own which I call <strong>thefileupload</strong>. This is the code for the method</p>
<h4>private void thefileupload(FileUpload upload)</h4>
<h4>{<br />
if (upload.HasFile)<br />
try<br />
{<br />
upload.SaveAs(&#8220;C:\\myUploads\\&#8221; + upload.FileName);</h4>
<h4>}<br />
catch (Exception ex)<br />
{<br />
Label1.Text = &#8220;ERROR: &#8221; + ex.Message.ToString();<br />
}<br />
else<br />
{<br />
Label1.Text = &#8220;You have not specified a file or the file has not been found.&#8221;;<br />
}<br />
}</h4>
<p>There is nothing fancy about this code. It is exactly the same as the previous bits. I just placed this code inside a method.</p>
<p>If you want the file upload functionality to work make sure that the destination folder on the server is  writable for the account used by ASP.NET. If ASP.NET is not enabled to write to the folder you want, you can enable it using the folder&#8217;s properties. If you want to permit your users to upload large files you should overwrite in the <strong>web.config</strong> file, the default size limitation which is <strong>4MB</strong> (4096kb)</p>
<p>Hope it helps.</p>
<p>If you want the source code you can email me.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/22/using-the-fileupload-web-server-control-in-your-aspnet-website/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;h=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;Title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;title=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-fileupload-web-server-control-in-your-aspnet-website%2F&amp;t=Using%20the%20FileUpload%20web%20server%20control%20in%20your%20asp.net%20website" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" alt="Add to Furl" /></a></p>
<a name="pd_a_1126880"></a><div class="PDS_Poll" id="PDI_container1126880" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1126880.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1126880/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://answers.polldaddy.com">answers</a></span>
		</noscript>
Posted in .NET, asp.net 2.0, C#, Visual Studio 2005, Visual Studio 2008 Tagged: C#, FileUpload control, web server controls <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/684/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/684/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/684/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/684/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/684/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/684/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/684/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/684/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/684/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/684/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=684&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/22/using-the-fileupload-web-server-control-in-your-aspnet-website/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m02.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m02.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m02.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m02.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m02.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m02.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m02.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m02.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m02.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m02.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the wizard control in asp.net pages</title>
		<link>http://dotnetstories.wordpress.com/2008/11/22/using-the-wizard-control-in-aspnet-pages/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/22/using-the-wizard-control-in-aspnet-pages/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 21:18:19 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asp.net 2.0]]></category>
		<category><![CDATA[wizard control]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=676</guid>
		<description><![CDATA[Using the wizard control in asp.net pages to create step by step navigation schemes for data collection<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=676&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I would like to talk a bit about a web server control that has been implemented back in the Asp.Net 2.0 Framework but for some reason even if it is very useful, many developers do not know how to use it and when to use it.  This is the <strong>Wizard</strong> control. Basically this control allow us to create a mechanism that requires the collection of data over a number of steps. You can do that with multiple pages but in this case you need to manage the state and the data between the pages.</p>
<p>This wizard contains a number of steps that are easiy configurable.</p>
<p>We will create a little asp.net application with C# to demonstrate the use of this control</p>
<p>1) Lanch VS and choose C# as your preferred language</p>
<p>2) Choose Asp.Net Web Application from the templates</p>
<p>3) Give your project a name</p>
<p>4) Place a wizard control from the Toolbox on the <em>Default.aspx</em> page. Leave the default name.Select the wizard control and click the smart tag (the arrow in the right-hand upper corner) and choose <strong>Auto format</strong>.</p>
<p>Choose a format of your choice from the available ones. You can always change the colors and fonts of a pre-decided format from the <strong>styles</strong> area of the properties window.</p>
<p>5) I know it is a little early but run your application.</p>
<p>You will see that you have <em>Previous</em>,<em>Next</em> and <em>Finish</em> buttons. Just click them and play around.</p>
<p>Close the page and in your <em>default.aspx</em> just select the wizard control.From the properties window, find the <em>wizardsteps</em>, <em>Collection</em>.</p>
<p>Click on the ellipsis and you will see a picture like the one below (in my case it has the complete steps)</p>
<p style="text-align:center;"><a href="http://dotnetstories.files.wordpress.com/2008/11/wizard.jpg"><img class="size-full wp-image-679 aligncenter" title="wizard" src="http://dotnetstories.files.wordpress.com/2008/11/wizard.jpg?w=460&#038;h=287" alt="wizard" width="460" height="287" /></a></p>
<p>In my example (because I work for a company that organises events on I.T) I have created a step-by step navigation scheme to create a feedback form.</p>
<p>In this window you can create as many steps you want and call them as you wish. Pay more attention to the <strong>StepType</strong> property.</p>
<p>After you finish adding steps, click the <strong>OK</strong> button.</p>
<p>Select the wizard control again. Click the smart tag (the arrow in the right-hand upper corner).</p>
<p>Select the step you want and drag and drop the controls you want onto this step. In my example I have a step called <strong>Name</strong> and i place a textbox control in this step. I follow the same pattern for all the other steps.</p>
<p>If you notice carefully  in the properties window you will see 2 properties <strong>CancelDestinationPageUrl, FinishDestinationPageUrl.</strong></p>
<p>You can create 2 new .aspx pages and name them, <strong>Cancel.aspx</strong> and <strong>Finish.aspx</strong>.</p>
<p>In the <strong>Cancel.aspx</strong> write something like &#8220;you have chosen to cancel&#8230;&#8221;</p>
<p>In the <strong>Finish.aspx</strong> write something like &#8220;Thank you&#8221;</p>
<p>Then you just set the values of the above properties to the respective pages.</p>
<p>Now you can run your application and see all the steps(and in each step the controls you have added) you have created and click the <strong>Next</strong> and <strong>Previous,Finish,Cancel</strong> buttons on the wizard.</p>
<p>Hope everything makes sense and if you need the source code send me an email.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/22/using-the-wizard-control-in-aspnet-pages/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m04.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;h=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m04.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m04.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m04.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m04.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m04.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;Title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m04.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;title=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m04.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m04.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F22%2Fusing-the-wizard-control-in-aspnet-pages%2F&amp;t=Using%20the%20wizard%20control%20in%20asp.net%20pages" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m04.png" alt="Add to Furl" /></a></p>
Posted in asp.net 2.0, C# Tagged: asp.net 2.0, C#, wizard control <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/676/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/676/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/676/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/676/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/676/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/676/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/676/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/676/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/676/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/676/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=676&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/22/using-the-wizard-control-in-aspnet-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/wizard.jpg" medium="image">
			<media:title type="html">wizard</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m04.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m04.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m04.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m04.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m04.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m04.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m04.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m04.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m04.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m04.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>The AdRotator web server control</title>
		<link>http://dotnetstories.wordpress.com/2008/11/21/the-adrotator-web-server-control/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/21/the-adrotator-web-server-control/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 19:17:38 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Sql Server 2005]]></category>
		<category><![CDATA[VB 2005]]></category>
		<category><![CDATA[asp.net 2.0]]></category>
		<category><![CDATA[adrotator control]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=656</guid>
		<description><![CDATA[The AdRotator web server control is a control we can use in our asp.net pages to display to the user ads of our choice<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=656&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hello all,</p>
<p>I had some requests to write a post about the <strong>Adrotator</strong> control and how it can be used to serve up random banners in our web site.I thought that was a good idea and a great excuse to break away from the LINQ stuff&#8230;</p>
<p>I will demonstrate the use of this control with an example (C# version).I will use an XML file that will serve as the source for my banners.</p>
<p>The <strong>AdRotator</strong> control of course was included in the previous versions of Visual Studio and framework version, ASP.Net 2.0 to be exact.</p>
<p>1) Launch Visual Studio</p>
<p>2) Create a new project. More specifically choose <strong>C#</strong>, and from the templates <strong>ASP.Net Web application</strong></p>
<p>3) Give a name to your project</p>
<p>4) From your toolbox just drag and drop an <strong>AdRotator</strong> Control in the <em>Default.aspx</em> page</p>
<p>5) Click on your project from the Solution explorer and create an <strong>Images</strong> folder</p>
<p>6) Place your images (i am going to use images of mine) in the folder above</p>
<p>7) Add a new item to your project. It will be an XML file. Name it &#8220;banner.xml&#8221;. It is a good idea to place it in the <strong>App_Data</strong> special folder that is already created in your project structure.</p>
<p>8) Copy and paste the following XML code inside the &#8220;bannel.xml&#8221; file.</p>
<h4>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;<br />
&lt;Advertisements xmlns=&#8221;http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File&#8221;&gt;</h4>
<h4>&lt;Ad&gt;<br />
&lt;ImageUrl&gt;~/images/ajax-logo.gif&lt;/ImageUrl&gt;<br />
&lt;NavigateUrl&gt;http://www.asp.net/ajax/&lt;/NavigateUrl&gt;<br />
&lt;AlternateText&gt;ASP.NET AJAX is a free framework for quickly creating efficient and interactive Web applications that work across all popular browsers&lt;/AlternateText&gt;<br />
&lt;Keyword&gt;asp.net ajax&lt;/Keyword&gt;<br />
&lt;Impressions&gt;100&lt;/Impressions&gt;</h4>
<h4>&lt;/Ad&gt;</h4>
<h4>&lt;Ad&gt;<br />
&lt;ImageUrl&gt;~/images/asp-logo.png&lt;/ImageUrl&gt;<br />
&lt;NavigateUrl&gt;http://www.asp.net&lt;/NavigateUrl&gt;<br />
&lt;AlternateText&gt;ASP.NET is a free technology that allows anyone to create a modern web site&lt;/AlternateText&gt;<br />
&lt;Keyword&gt;Asp.Net&lt;/Keyword&gt;<br />
&lt;Impressions&gt;150&lt;/Impressions&gt;<br />
&lt;/Ad&gt;<br />
&lt;Ad&gt;<br />
&lt;ImageUrl&gt;~/images/NET-logo.png&lt;/ImageUrl&gt;<br />
&lt;NavigateUrl&gt;http://www.microsoft.com/NET/&lt;/NavigateUrl&gt;<br />
&lt;AlternateText&gt;The .NET Framework is Microsoft&#8217;s comprehensive and consistent programming model for building applications &lt;/AlternateText&gt;<br />
&lt;Keyword&gt;.NET&lt;/Keyword&gt;<br />
&lt;Impressions&gt;250&lt;/Impressions&gt;<br />
&lt;/Ad&gt;</p>
<p>&lt;/Advertisements&gt;</h4>
<p>If you want to find more about the attributes of the control and how we include them in the .xml file, have a a look <a href="http://msdn.microsoft.com/en-us/library/d5kd8aka.aspx" target="_blank">here</a></p>
<p>Make sure you change the name of the images in the <strong>&lt;ImageUrl&gt;</strong> attribute to reflect the images you placed in the Images folder in your project.<br />
9) Now select the <strong>AdRotaror</strong> control and from the properties window in VS select the property called <em>AdvertisementFile</em> .Click on the <em>ellipsis</em> button and navigate until you find the &#8220;banners.xml&#8221; file.</p>
<p>10) Run your application and hit F5 (refresh) many times from your keyboard to see all the banners specified in the .xml file appearing randomly according to their weight (Impressions attribute).<br />
<a href="http://msdn.microsoft.com/en-us/library/d5kd8aka.aspx" target="_blank"></a></p>
<p>That is it folks!!! Congrats. you have your dynamic page displaying your feature banners.</p>
<p>If you want to enable some sort of filtering in your ads, you can do so.</p>
<p>If you place a <strong>DropDownlist</strong> control in your <em>default.aspx</em> page and add as items these names</p>
<ul>
<li>asp.net ajax</li>
<li>Asp.Net</li>
<li>.NET</li>
</ul>
<p>Enable <strong>AutoPostBack </strong>property for this control.By clicking on this control in the <strong>Default.aspx.cs,</strong></p>
<p>you will be presented with the event handling routine for the standard event(SelectedIndexChanged).</p>
<h4>protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
AdRotator1.KeywordFilter = DropDownList1.SelectedItem.Value;<br />
}</h4>
<p>We set the property <strong>Keywordfilter</strong> of the AdRotator control to the value of the selected item from the list, thus selecting only the banners that match the keyword.</p>
<p>Run your application and choose different items from the dropdownlist . In my example there are 3 banners with 3 different keywords so only one banner will be shown every time you choose a different item.</p>
<p>I would like to show you how you can retrieve the ads if we have a Sql Server database as our source file.</p>
<p>1) First we need to create the database . Select the <strong>App_Data</strong> special folder and add a new item, <strong>a Sql Server Database. </strong>Call it <strong>banners.mdf</strong>.We need to create a table and we will call it <strong>ads</strong></p>
<p>The definition for this table, for fields and data types could be</p>
<p><strong>Field names</strong> <strong> Data type</strong></p>
<p>id                    -&gt;      int    -&gt; primary key and identity column</p>
<p>ImageUrl         -&gt; nvarchar(250) -&gt; not null</p>
<p>NavigateUrl     -&gt; nvarchar(250) -&gt; not null</p>
<p>AlternateText  -&gt; nvarchar(250) -&gt; not null</p>
<p>keyword          -&gt; nvarchar(50) -&gt; not null</p>
<p>impressions    -&gt; int -&gt; not null</p>
<p>Populate the table with the following data (for 3 rows)</p>
<p><strong>1st row</strong></p>
<p>ImageUrl = ~/images/asp-logo.png<br />
NavigateUrl=http://www.asp.net<br />
AlternateText=ASP.NET is a free technology that allows anyone to create a modern web site<br />
Keyword=Asp.Net<br />
Impressions=150<br />
<strong>2nd row</strong></p>
<p>ImageUrl = ~/images/ajax-logo.gif<br />
NavigateUrl=http://www.asp.net/ajax<br />
AlternateText=ASP.NET AJAX is a free framework for quickly creating efficient and interactive Web applications that work across all popular browsers<br />
Keyword=asp.net ajax<br />
Impressions=100</p>
<p><strong>3rd row</strong></p>
<p>ImageUrl = ~/images/NET-logo.png<br />
NavigateUrl=http://www.microsoft.com/NET<br />
AlternateText=The .NET Framework is Microsoft&#8217;s comprehensive and consistent programming model for building applications<br />
Keyword=.Net<br />
Impressions=250</p>
<p>Now create a new .aspx page and make it the <em>Start page</em>.Name it as you want.</p>
<p>Place a new AdRotator control in the newly created page.</p>
<p>Now we must have a datasource control that points to the database we created and tie this datasource control with the rotator control.</p>
<p>Click on the little arrow in the rotator control and choose <em>New Data Source</em>, choose <em>database</em> from the window and then from the <em>Configure DataSource</em> window, select the <strong>banner</strong> database and click <em>Next</em>.</p>
<p>Then select the <strong>ads</strong> table and select all the fields from the table. Test the query and click <em>Finish</em>.</p>
<p>Run your application and see the ads to apper now from the database.</p>
<p>You can email me if you want the source code or leave a comment.</p>
<p>Hope it helps!!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/21/the-adrotator-web-server-control/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;h=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;Title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;title=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fthe-adrotator-web-server-control%2F&amp;t=The%20AdRotator%20web%20server%20control" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" alt="Add to Furl" /></a></p>
<a name="pd_a_1126880"></a><div class="PDS_Poll" id="PDI_container1126880" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1126880.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1126880/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://answers.polldaddy.com">answers</a></span>
		</noscript>
Posted in asp.net 2.0, C#, Sql Server 2005, VB 2005 Tagged: adrotator control, asp.net 2.0, C# <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/656/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/656/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/656/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/656/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/656/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/656/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/656/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/656/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/656/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/656/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=656&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/21/the-adrotator-web-server-control/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m05.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m05.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m05.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m05.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m05.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m05.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m05.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m05.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m05.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m05.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>XML Literals and Visual basic 9.0</title>
		<link>http://dotnetstories.wordpress.com/2008/11/21/xml-literals-and-visual-basic-90/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/21/xml-literals-and-visual-basic-90/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 22:58:37 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML Literals]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=638</guid>
		<description><![CDATA[In this post I would like to demonstrate with some examples a new feature of Visual Basic 9.0 which is XML Literals<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=638&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I would like to demonstrate with some examples a new feature of Visual Basic 9.0 which is <strong>XML Literals</strong>.C# does not support XML Literals.</p>
<p>If you want to find out about the reasons that VB chose to support XML Literals and C# did not, click <a href="http://www.infoq.com/news/2007/03/CSharp-XML" target="_blank">here</a></p>
<p>If you want to look more into this have a look <a href="http://steve.emxsoftware.com/LINQ/XLinq+has+me+wanting+to+code+in+VBNET" target="_blank">here</a> as well.</p>
<p>Basically if you are a C# fanatic (as many people out there), If you have a project that relies heavily on XML, you will be better off if you choose VB 9.0 instead. Or if it is a mixed project you can use VB 9.0 in parts of a project where literal XML would be useful, and C# in the parts of the project&#8230;</p>
<p>In the past If we wanted to have an XML document from code we had to use API&#8217;s to create elements and attach attributes&#8230;</p>
<p>In VB 9.0 you can create XML documents in code without using strings or APIs.</p>
<p>We need to start a new project in Visual Studio to examine some of these new features.</p>
<p>1) Launch Visual Studio 2008</p>
<p>2) Start a new project, choose VB as your preferred language and then choose Console Application as your template</p>
<p>3) Name the project &#8220;XmlLiterals&#8221; or any other name of your choice</p>
<p>Inside the <strong>Module1.vb</strong> ,place this code</p>
<h4>Dim thexml = &lt;books&gt;<br />
&lt;book paperback=&#8221;yes&#8221; cdrom=&#8221;no&#8221;&gt;23&lt;/book&gt;<br />
&lt;/books&gt;Console.WriteLine(thexml)</p>
<p>Console.ReadLine()</h4>
<p>If you run the application it will not break and it will print our small XML document on the screen.</p>
<p>We could re-write the above snippet of code differently. Comment out the lines above.</p>
<p>Have a look at the code below</p>
<h4>Dim thexml = &lt;books&gt;<br />
<span style="color:#ff0000;">&lt;%=</span>&lt;book paperback=&#8221;yes&#8221; cdrom=&#8221;no&#8221;&gt;23&lt;/book&gt; <span style="color:#ff0000;">%&gt;</span><br />
&lt;/books&gt;Console.WriteLine(thexml)</p>
<p>Console.ReadLine()</h4>
<p>and paste it in the <strong>Module1.vb</strong></p>
<p><strong></strong> If you run the application again, you will get the same output.</p>
<p>The syntax in red color is called<em> embedded code block</em>.</p>
<p>That sort of syntax allows us to replace the xml code with other values such as variables.</p>
<p>I would like to add a class in my module in order to demonstrate XML Literals better.</p>
<p>Paste the code below after the code for the module ends (End Module)</p>
<h4>Class Book</h4>
<h4>Private _author As String</h4>
<h4>Private _pub_year As String</h4>
<h4>Private _stock As Integer</h4>
<h4>Public Property Author() As String</h4>
<h4>Get</h4>
<h4>Return _author</h4>
<h4>End Get</h4>
<h4>Set(ByVal value As String)</h4>
<h4>_author = value</h4>
<h4>End Set</h4>
<h4>End Property</h4>
<h4>Public Property Pub_Year() As String</h4>
<h4>Get</h4>
<h4>Return _pub_year</h4>
<h4>End Get</h4>
<h4>Set(ByVal value As String)</h4>
<h4>_pub_year = value</h4>
<h4>End Set</h4>
<h4>End Property</h4>
<h4>Public Property Stock() As Integer</h4>
<h4>Get</h4>
<h4>Return _stock</h4>
<h4>End Get</h4>
<h4>Set(ByVal value As Integer)</h4>
<h4>_stock = value</h4>
<h4>End Set</h4>
<h4>End Property</h4>
<h4>End Class</h4>
<p>This class is called <strong>Book</strong> and it has 3 properties, <em>author,pub_year,stock</em>.</p>
<p>Now what I need to do is to create a collection of these objects and assign them some values.</p>
<p>I can do that by using a function which I call <em>Createbooks</em>.</p>
<p>Here is the code. It is pretty simple really&#8230;</p>
<h4>Function CreateBooks() As List(Of Book)</h4>
<h4>Dim book1 As New Book() With {.Author = &#8220;Ian McEwan&#8221;, .Title = &#8220;Atonement&#8221;, .Pub_Year = 2002, .Stock = 23}</h4>
<h4>Dim book2 As New Book() With {.Author = &#8220;Sylvia Plath&#8221;, .Title = &#8220;The Colossus&#8221;, .Pub_Year = 1980, .Stock = 19}</h4>
<h4>Dim book3 As New Book() With {.Author = &#8220;Jane Austen&#8221;, .Title = &#8220;Pride and Prejudice&#8221;.Pub_Year = 1976, .Stock = 11}</h4>
<h4>Dim returnList As New List(Of Book)</h4>
<h4>returnList.Add(book1)</h4>
<h4>returnList.Add(book2)</h4>
<h4>returnList.Add(book3)</h4>
<h4>Return returnList</h4>
<h4>End Function</h4>
<p>Place the function inside your module, just after <em>Sub Main()</em>.</p>
<p>Comment out these lines</p>
<h4>&#8216; Dim thexml = &lt;books&gt;<br />
&#8216;     &lt;%= &lt;book paperback=&#8221;yes&#8221; cdrom=&#8221;no&#8221;&gt;23&lt;/book&gt; %&gt;<br />
&#8216;     &lt;/books&gt;</h4>
<p>Inside your  <em>Sub Main()</em> store the list of objects in a variable.</p>
<p>So basically type something like this</p>
<h4>Dim mybooks = CreateBooks()</h4>
<p>Then in order  to find all the values for each book i need to write something like this</p>
<h4>Dim bookitems = From book In mybooks _</h4>
<h4>Select &lt;Book Author=&lt;%= book.Author %&gt; Title=&lt;%= book.Title %&gt; Published_year=&lt;%= book.Pub_Year %&gt;&gt; Stock=&lt;%= book.Stock %&gt;&lt;/Book&gt;</h4>
<h4>Dim theXML = &lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; standalone=&#8221;yes&#8221;?&gt;</h4>
<h4>&lt;Books&gt;</h4>
<h4>&lt;%= bookitems %&gt;</h4>
<h4>&lt;/Books&gt;</h4>
<h4>Console.WriteLine(theXML)</h4>
<h4>Console.ReadLine()</h4>
<p>After I retrieve all the elements I create a new XML document and place them in there.</p>
<p>Run your application. In the console window you will see the <strong>Books</strong> element and then 3 seperate <strong>book</strong> elements each with attribute and values.</p>
<p>In order to find out what kind of object is the &#8220;theXML&#8221; variablejust add this line of code</p>
<h4>Console.WriteLine(TypeName(theXML))</h4>
<p>If your run your application you will see that .Net refers to it as <strong>XDocument.</strong></p>
<p><strong><br />
</strong></p>
<p>Comment out the line above.</p>
<p>So what if I wanted to print one item in the screen? What if I wanted to get hold of the name of the author of the first book?</p>
<p>This is how I navigate the <strong>XDocument</strong> object tree.</p>
<h4>Dim myfirstbookauthor As String = theXML.&lt;Books&gt;.&lt;Book&gt;(0).@Author<br />
Console.WriteLine(myfirstbookauthor)</h4>
<p>Run you application and will get &#8220;Ian McEwan&#8221;.</p>
<p>If you wanted to loop through all the items in the object tree and get a specific attribute(like the book&#8217;s title), this is one way to do it.</p>
<h4>For Each book In theXML.&lt;Books&gt;.&lt;Book&gt;<br />
Console.WriteLine(book.@Title)<br />
Next</h4>
<p>Make sure that you comment these lines out, so you do not get confused</p>
<h4>&#8216;Dim myfirstbookauthor As String = theXML.&lt;Books&gt;.&lt;Book&gt;(0).@Author<br />
&#8216;Console.WriteLine(myfirstbookauthor)</h4>
<p>Run you application. In the Console window you will see these values,</p>
<h4>&#8220;Atonement&#8221;</h4>
<h4>&#8220;The Colossus&#8221;</h4>
<h4>&#8220;Pride and Prejudice&#8221;</h4>
<p>To recap, VB 9.0 treats XML Literals like String Literals, number Literals and allows you to work directly with XML.</p>
<p>If you need the source code email me&#8230;</p>
<p>Hope it helps!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/21/xml-literals-and-visual-basic-90/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;h=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;Title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;title=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F21%2Fxml-literals-and-visual-basic-90%2F&amp;t=XML%20Literals%20and%20Visual%20basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
<a name="pd_a_1123850"></a><div class="PDS_Poll" id="PDI_container1123850" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1123850.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1123850/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://www.polldaddy.com">survey</a></span>
		</noscript>
Posted in VB 9.0, Visual Studio 2008, XML Tagged: VB 9.0, XML, XML Literals <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/638/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/638/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/638/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/638/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/638/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/638/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/638/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/638/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/638/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/638/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=638&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/21/xml-literals-and-visual-basic-90/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>How to monitor and debug LINQ to SQL queries</title>
		<link>http://dotnetstories.wordpress.com/2008/11/19/how-to-monitor-and-debug-linq-to-sql-queries/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/19/how-to-monitor-and-debug-linq-to-sql-queries/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 15:00:05 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[c# 3.0]]></category>
		<category><![CDATA[Linq to Sql]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=613</guid>
		<description><![CDATA[How to monitor and debug LINQ to SQL queries<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=613&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In one of my previous <a href="http://dotnetstories.wordpress.com/2008/07/01/linq-to-sql-querying-the-pubs-database/">posts</a> where I tried to explain how to query an Sql Server database with LINQ to SQL, I said that LINQ to SQL queries get translated into commands that SQL Server understands. The LINQ runtime knows how to translate LINQ to SQL queries to T-SQL, the only language SQL Server knows!</p>
<p>We can see the communication between the Runtime and SQL Server using several tools.</p>
<p>Some tools are built into the Visual Studio 2008 sp1 for looking into the results of a LINQ query.</p>
<p>If you follow the exact same steps of my previous <a href="http://dotnetstories.wordpress.com/2008/07/01/linq-to-sql-querying-the-pubs-database/">post</a> until step 8 (the first example), then</p>
<p>you can put a breakpoint in this line</p>
<p><em>var tauthors = from ta in db.titleauthors<br />
select ta;</em></p>
<p>run your application now and then press F11 to move one step forward from the above statement</p>
<p>Then place your cursor in the <em>tauthors </em>variable and select the <strong>Results View</strong>.</p>
<p>It has all the instances of <strong>author</strong> entity that has been retrieved from the database and populated in the <strong>titleauthors</strong> class.</p>
<p>You can go throuch each one of them and their respective private fields.</p>
<p>see the picture below and consider it as a visual aid</p>
<p style="text-align:center;"><a href="http://dotnetstories.files.wordpress.com/2008/11/resultsview.jpg"><img class="size-full wp-image-615 aligncenter" title="resultsview" src="http://dotnetstories.files.wordpress.com/2008/11/resultsview.jpg?w=460&#038;h=287" alt="resultsview" width="460" height="287" /></a></p>
<p>That is one approach viewing-debugging the results before they actually executes</p>
<p>There is another tool available.</p>
<p>Fire the browser of your choice and type the following url from Scott&#8217;s Gu website</p>
<p>http://www.scottgu.com/blogposts/linqquery/sqlserverqueryvisualiser.zip</p>
<p>Scott includes this tool as an add-on on his website.</p>
<p>Download this tool to your desktop and then unzip it.</p>
<p>Go then to the <strong>Debug/bin</strong> folder , copy the <strong>SqlServerQueryVisualizer.dll</strong> and place it in the following folder</p>
<p><em>C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers</em></p>
<p>Save all your work. Close your project and exit Visual Studio</p>
<p>Fire up Visual Studio 2008 again and open your project again.</p>
<p>If you put a breakpoint in the same line,  run your application, press F11 and place your cursor above the</p>
<p><em>tauthors</em> variable. You will see a magnifier icon. Click on it. You will see a screen that looks like the one below</p>
<p style="text-align:center;"><a href="http://dotnetstories.files.wordpress.com/2008/11/scottvisualiser1.jpg"><img class="size-full wp-image-619 aligncenter" title="scottvisualiser1" src="http://dotnetstories.files.wordpress.com/2008/11/scottvisualiser1.jpg?w=460&#038;h=287" alt="scottvisualiser1" width="460" height="287" /></a></p>
<p>When you click on the magnifier icon, you will see the <strong>SQL Server Query Visualiser </strong>which shows the query that is going to be executed.</p>
<p>You can hit the &#8220;Execute&#8221; button to preview the results before they executed.If you want to see when commands are executed you can use a different tool called <strong>LINQ to SQL Debug Writer</strong>.</p>
<p><strong>LINQ to SQL Debug Writer </strong>is basically just a class that you add to your applications that outputs the generated T-SQL to the Debug window.</p>
<p>So you need to add another class to your project. Name it &#8220;class1.cs&#8221;</p>
<p>clear all the code in the class file and go to the following url</p>
<p>http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?List=4a6d97a9-b3b0-45a7-88a0-1a7f4819a678&amp;ID=11&amp;Source=http%3A%2F%2Fwww.u2u.info%2FBlogs%2FKris%2FLists%2FPosts%2FAllPosts.aspx</p>
<p>You will need to copy all the contents from this line</p>
<p><strong>Here&#8217;s the code:</strong></p>
<p>until the end&#8230;</p>
<p>and place it in the <strong>class1.cs</strong> file.</p>
<p>make sure you change this line inside the above file</p>
<pre class="code"><span style="color:#0000ff;">namespace</span> Vandermotten.Diagnostics

with whatever you named your project.</pre>
<p>Then you need to add this line</p>
<pre class="code">db.Log = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DebuggerWriter</span>();

<strong>immediately after this line</strong>

pubsDataContext db = new pubsDataContext();</pre>
<p>Save and run your application by placing the breakpoint in the same place.</p>
<p>Clear all windows (like watch,locals) and just make sure you have the &#8220;Output&#8221; window open.</p>
<p>Step into your code. You can see in the output window, LINQ to SQL runtime, generates the T-SQL and sends the statement to the SQL SERVER.With this tool we can see both what is executed and what is executed.</p>
<p>We can also use the SQL Server Profiler to watch the traffic between LINQ to SQL and SQL Server.</p>
<p>Select Sql Profiler from the Performance Tools, start a new trace,connect to your SQL SERVER ,accept all the defaults and hit the Run button.</p>
<p>If you run the application again and have this break point and run the code step by step,you can see the entire T-SQL statement that has been executed in the SQL profiler window.</p>
<p>Hope it helps&#8230;..</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/19/how-to-monitor-and-debug-linq-to-sql-queries/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;h=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;Title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;title=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F19%2Fhow-to-monitor-and-debug-linq-to-sql-queries%2F&amp;t=How%20to%20monitor%20and%20debug%20LINQ%20to%20SQL%20queries" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" alt="Add to Furl" /></a></p>
<a name="pd_a_1123850"></a><div class="PDS_Poll" id="PDI_container1123850" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1123850.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1123850/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://www.polldaddy.com">survey</a></span>
		</noscript>
Posted in c# 3.0, LINQ, Visual Studio 2008 Tagged: Linq to Sql <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/613/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=613&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/19/how-to-monitor-and-debug-linq-to-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/resultsview.jpg" medium="image">
			<media:title type="html">resultsview</media:title>
		</media:content>

		<media:content url="http://dotnetstories.files.wordpress.com/2008/11/scottvisualiser1.jpg" medium="image">
			<media:title type="html">scottvisualiser1</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m03.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m03.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m03.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m03.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m03.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m03.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m03.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m03.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m03.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m03.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Nullable data types in Visual Basic 9.0</title>
		<link>http://dotnetstories.wordpress.com/2008/11/17/nullable-data-types-in-visual-basic-90/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/17/nullable-data-types-in-visual-basic-90/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 12:16:09 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[VB 9.0]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=605</guid>
		<description><![CDATA[Nullable data types allow you to create data types like integers and initialize them to nothing.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=605&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this post I would like to talk about language improvements in visual basic 9.0 and more specifically about nullable data types.</p>
<p>The largest improvement in Visual basic 9.0 is LINQ. So all these enhancements that were made in the VB 9.0 language (the same goes for c# 3.0 enhancements) had LINQ in mind and how LINQ will be able to work.</p>
<p><strong>Nullable data types</strong> enable us to create data types e.g integers and set them-initialise them to the value nothing, <strong>null</strong>.</p>
<p>In our database design we often have tables where fields are allowed to have <strong>NULL</strong>.</p>
<p>Prior to Visual Basic 9.0 one should turn the null value from the database into a zero value in the application<br />
<strong>Nullable data types</strong> help us to avoid this mismatch in LINQ to SQL.</p>
<p>The problem is that representing a <strong>null</strong> (nothing) value with zero is wrong, because <strong>null</strong> means something that is uknown and by setting it to zero, well you set it to something that is known&#8230;.</p>
<p>In order to demonstrate this enhancement-new feature I will create a simple Asp.Net application using VB and Visual Studio 2008.</p>
<p>1) Launch Visual Studio 2008</p>
<p>2) Create a new project (ASP.NET web application)  and choose VB as the project&#8217;s language</p>
<p>3) Name it &#8220;<em>nullabledata</em>&#8221; or any other name you want</p>
<p>4) Add a button in the default.aspx page</p>
<p>5) Double click in the button</p>
<p>6) In the event handling routine that is created just type the following</p>
<p><strong>Dim mynum As Integer? = 4<br />
Dim myothernum As Integer? = Nothing<br />
Dim myres As Integer = 0</strong></p>
<p><strong>myres = mynum + myothernum</strong></p>
<p><strong>Response.Write(IsNothing(myres).ToString())</strong></p>
<p>by adding the <strong>?</strong> operator after the data type, we indicate that the variable <strong>mynum</strong> can be set to nothing.</p>
<p>We declare another variable in this statement</p>
<p><strong>Dim myothernum As Integer? = Nothing</strong></p>
<p>This can only be valid in VB 9.0</p>
<p>Try and run your application by hitting F5.</p>
<p>Click on the button. You will receive an error &#8211; exception.</p>
<p>the problem is that the variable with the name <strong>myres</strong> is not nullable.</p>
<p>When you add 4 with an uknown value you do not get 4. You get an uknown value.</p>
<p>The solution to this problem is to create another variable that is nullable this time.</p>
<p><strong>Dim myfinalres As Integer?</strong></p>
<p>comment out these lines</p>
<p><strong>myres = mynum + myothernum</strong></p>
<p><strong>Response.Write(IsNothing(myres).ToString())</strong></p>
<p>and type these lines</p>
<p><strong>myfinalres = mynum + myothernum</strong></p>
<p><strong>Response.Write(IsNothing(myfinalres).ToString())</strong></p>
<p>Now if you run the application again and press the button you will receive the value of <strong>Nothing</strong>.</p>
<p>Hope it helps!!!</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/17/nullable-data-types-in-visual-basic-90/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;h=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;Title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;title=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F17%2Fnullable-data-types-in-visual-basic-90%2F&amp;t=Nullable%20data%20types%20in%20Visual%20Basic%209.0" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
<p style="text-align:left;"><a name="pd_a_1114751"></a><div class="PDS_Poll" id="PDI_container1114751" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1114751.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1114751/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://www.polldaddy.com">online surveys</a></span>
		</noscript></p>
Posted in LINQ, VB 9.0, Visual Studio 2008 Tagged: LINQ, VB 9.0, Visual Studio 2008 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/605/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=605&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/17/nullable-data-types-in-visual-basic-90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net 4 Framework poster</title>
		<link>http://dotnetstories.wordpress.com/2008/11/16/net-4-framework-poster/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/16/net-4-framework-poster/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 17:41:44 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.Net 4]]></category>
		<category><![CDATA[poster]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=598</guid>
		<description><![CDATA[Brad Adams has created a very nice and cool poster with the new features in .Net Framework 3.5 SP1 and .Net Framework 4.0.
For more information click here
The poster is available in pdf version and in DeepZoom version.

Posted in .NET Tagged: .NET, .Net 4, poster      <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=598&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Brad Adams has created a very nice and cool poster with the new features in .Net Framework 3.5 SP1 and .Net Framework 4.0.</p>
<p>For more information click <a href="http://blogs.msdn.com/brada/archive/2008/10/29/net-framework-4-poster.aspx" target="_blank">here</a></p>
<p>The poster is available in <a href="http://brad_abrams.members.winisp.net/Projects/PDC2008/PDC2008-NETFX4.pdf" target="_blank">pdf</a> version and in <a title=".NET Framework 4 Poster - DeepZoom Version" href="http://tinyurl.com/DotNetFramework4PosterDeepZoom" target="_blank">DeepZoom</a> version.</p>
<p style="text-align:left;"><a href="http://www.facebook.com/sharer.php?u=http://dotnetstories.wordpress.com/2008/11/16/net-4-framework-poster/" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" alt="Add to Facebook" /></a><a href="http://www.newsvine.com/_wine/save?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;h=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" alt="Add to Newsvine" /></a><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" alt="Add to Digg" /></a><a href="http://del.icio.us/post?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" alt="Add to Del.icio.us" /></a><a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" alt="Add to Stumbleupon" /></a><a href="http://reddit.com/submit?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" alt="Add to Reddit" /></a><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;Title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" alt="Add to Blinklist" /></a><a href="http://ma.gnolia.com/bookmarklet/add?url=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;title=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" alt="Add to Ma.gnolia" /></a><a href="http://www.technorati.com/faves?add=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" alt="Add to Technorati" /></a><a href="http://www.furl.net/storeIt.jsp?u=http%3A%2F%2Fdotnetstories.wordpress.com%2F2008%2F11%2F16%2Fnet-4-framework-poster%2F&amp;t=.Net%204%20Framework%20poster" target="_blank"><img style="border:0;margin:0;padding:0;" src="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" alt="Add to Furl" /></a></p>
Posted in .NET Tagged: .NET, .Net 4, poster <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnetstories.wordpress.com/598/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnetstories.wordpress.com/598/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnetstories.wordpress.com/598/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnetstories.wordpress.com/598/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnetstories.wordpress.com/598/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnetstories.wordpress.com/598/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnetstories.wordpress.com/598/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnetstories.wordpress.com/598/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnetstories.wordpress.com/598/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnetstories.wordpress.com/598/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=598&subd=dotnetstories&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotnetstories.wordpress.com/2008/11/16/net-4-framework-poster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecbfd3584f3b2c0c3f528bacdfc15e0a?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">fofo</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb201m01.png" medium="image">
			<media:title type="html">Add to Facebook</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb202m01.png" medium="image">
			<media:title type="html">Add to Newsvine</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb203m01.png" medium="image">
			<media:title type="html">Add to Digg</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb204m01.png" medium="image">
			<media:title type="html">Add to Del.icio.us</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb205m01.png" medium="image">
			<media:title type="html">Add to Stumbleupon</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb206m01.png" medium="image">
			<media:title type="html">Add to Reddit</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb207m01.png" medium="image">
			<media:title type="html">Add to Blinklist</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb208m01.png" medium="image">
			<media:title type="html">Add to Ma.gnolia</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb209m01.png" medium="image">
			<media:title type="html">Add to Technorati</media:title>
		</media:content>

		<media:content url="http://getsocialserver.files.wordpress.com/2008/05/gsb210m01.png" medium="image">
			<media:title type="html">Add to Furl</media:title>
		</media:content>
	</item>
		<item>
		<title>Common mistakes and misconceptions with CSS</title>
		<link>http://dotnetstories.wordpress.com/2008/11/10/common-mistakes-and-misconceptions-with-css/</link>
		<comments>http://dotnetstories.wordpress.com/2008/11/10/common-mistakes-and-misconceptions-with-css/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 20:44:08 +0000</pubDate>
		<dc:creator>fofo</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[IE8]]></category>

		<guid isPermaLink="false">http://dotnetstories.wordpress.com/?p=570</guid>
		<description><![CDATA[Common mistakes and misconceptions with CSS,media queries,class selectors,id selectors...<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnetstories.wordpress.com&blog=1661705&post=570&subd=dotnetstories&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In this long post, I will try to highlight some mistakes that are made by many designers-developers using CSS. Many of those mistakes have a simple explanation but if you do not know the answer can cause anxiety and frustration. I will also try to clarify some misconceptions regarding the use of CSS.</p>
<p><strong><span style="text-decoration:underline;">The order of the <em>style</em> and <em>link</em> elements in the HEAD section of the HTML/XHTML matters</span></strong></p>
<p>Recently I received an anxious phone call from a friend of mine, a web enthusiast. He had a simple document and he had defined an internal stylesheet and an external stylesheet to style the various elements in his document which is not a best practice to say the least&#8230;</p>
<p>He wanted to style the H1 elements in his document. So he typed in the HEAD section of the document the following</p>
<h4>&lt;style type=&#8221;text/css&#8221;&gt;</h4>
<h4>h1{</p>
<p>color:maroon;</p>
<p>}</h4>
<h4>&lt;/style&gt;</h4>
<p>just below this statement there was a link to an external stylesheet</p>
<h3>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;test1.css&#8221; /&gt;</h3>
<p>inside this stylesheet there is the following declaration</p>
<h3>h1{</p>
<p>color:aqua;</h3>
<h3>}</h3>
<p>But my friend paid no attention to this&#8230;. After all declarations in a <em>style </em>element overwrite those in an external stylesheet. Much to his surprise when he viewed the page with IE,Firefox,Opera he saw that the color of the <strong>H1 </strong>tags was &#8220;aqua&#8221; instead of &#8220;maroon&#8221; which was specified in the internal stylesheet. What happened is this. It is true that internal stylesheet&#8217;s property values overwrite<em> </em>those values for the same element in an external stylsheet <strong>but only when the &lt;style&gt;&lt;/style&gt; tags are specified after the &lt;link rel=&#8230;.&gt; element. </strong>In our case the <strong>&lt;link element &#8230;&gt; </strong>is specified after and that is why the values of the external link prevail.</p>
<p><strong><span style="text-decoration:underline;">Be careful of the shorthand notation</span></strong></p>
<p>When we want to specify values for related properties of a particular element we can do so in a single declaration.</p>
<p>for example we can do this</p>
<h3>margin: 1em 3em 4em 5em;</h3>
<p>This is equivalent with this</p>
<h3>margin-top: 1em;</h3>
<h3>margin-right: 3em;</h3>
<h3>margin-bottom: 4em;</h3>
<h3>margin-left: 5em;</h3>
<p>a very common mistake is to presume that if we leave blank(not set a value) this will result to 0em=0.</p>
<p>well if you write this (and please remember that we go from top-&gt;right-&gt;bottom-&gt;left)</p>
<h3>margin: 1em 3em 4em;</h3>
<p>the missing side is assigned the same value as the one opposite it. So in this case with the shorthand notation used above we have</p>
<p><em>margin-top: 1em;</em></p>
<p><em>margin-right: 3em;</em></p>
<p><em>margin-bottom: 4em;</em></p>
<p><strong>margin-left: 3em;</strong></p>
<p>The margin-left value is equal to 3em and not to zero.</p>
<p>Let&#8217;s see another example that falls in the same category. I use all the time the shorthand notation to specify values for the background property.</p>
<p>for example</p>
<h3>background: #000 url(myimage.jpg) no-repeat fixed left top;</h3>
<p>this is of course equivalent  with this</p>
<h3>background-color: #000;</h3>
<h3>background-image:url(myimage.jpg);</h3>
<h3>background-repeat:no-repeat;</h3>
<h3>background-attachment:fixed;</h3>
<h3>background-position:left top;</h3>
<p>Please try to use this order as it was presented here. Some people think if we omit one value in the shorthand notation, that means that simply there is no value for this property. Well, this is not the case.The initial value will be assigned to the missing property.</p>
<p>Initial value is the value for a property when there in no value specified for that property and it is not inherited. The initial value for each property is specified in the CSS specification.</p>
<p>so for the property in question ,<em>background</em>, the initial values for the</p>
<h3>background-color:transparent;</h3>
<h3>background-repeat:repeat;</h3>
<h3>background-attachment:scroll;</h3>
<h3>background-position: 0% 0%;</h3>
<p>If you write for example</p>
<p><strong>background-color:#000;</strong></p>
<p><strong>background:url(myimage.jpg);</strong></p>
<p>The background color will not be <strong>black, </strong>because this value #000 will be overwritten in the shorthand notation by this value <strong>background-color:transparent;</strong></p>
<p><strong>So, do not mix shorthand and standard notation.</strong></p>
<p><strong><span style="text-decoration:underline;">Do not omit the Doctype declaration</span></strong></p>
<p>If you omit the doctype declaration, e.g</p>
<p><em>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;</em><a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><em>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</em></a><em>&#8220;&gt;</em></p>
<p><em>&lt;html xmlns=&#8221;</em><a href="http://www.w3.org/1999/xhtml"><em>http://www.w3.org/1999/xhtml</em></a><em>&#8220;&gt;</em></p>
<p>the browser will always render the document in quirks mode and in most cases we do not want that.</p>
<p>By rendering in the quirks mode we will see our web site showing in a way we do not want.</p>
<p>For example the <strong>Internet Explorer 5 box model</strong> will kick off instead of the normal <strong>CSS box model</strong> and all the dimensions will be calculated according to this model and not the <strong>CSS box model</strong> as it was defined in the CSS2.1 speci