<?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/"
	>

<channel>
	<title>Emad Mokhtar&#039;s Framework</title>
	<atom:link href="http://www.emadmokhtar.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emadmokhtar.com</link>
	<description>Born To Be Geek</description>
	<lastBuildDate>Sat, 20 Apr 2013 18:54:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How do I learn?</title>
		<link>http://www.emadmokhtar.com/2013/04/how-do-i-learn/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-do-i-learn</link>
		<comments>http://www.emadmokhtar.com/2013/04/how-do-i-learn/#comments</comments>
		<pubDate>Sat, 20 Apr 2013 14:34:31 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[carftsmanship]]></category>
		<category><![CDATA[coder]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programmer]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=972</guid>
		<description><![CDATA[I’ve got many questions from young developers who want to learn programming and be professionals, I thought of writing this article to give them a glance about how I learn software stuff. I want to tell you I’m still learning&#8230; ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.brainyquote.com/quotes/quotes/a/abrahamlin109275.html" target="_blank"><img title="abrahamlincoln109275" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; float: none; margin-left: auto; display: block; border-top-width: 0px; margin-right: auto" border="0" alt="abrahamlincoln109275" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/abrahamlincoln109275.jpg" width="620" height="400"></a></p>
<p>I’ve got many questions from young developers who want to learn programming and be professionals, I thought of writing this article to give them a glance about how I learn software stuff. I want to tell you I’m still learning and I’ll always pursuit knowledge and being professional software craftsman, and you should consider the same, believe me if you stop learning, you’ll become outdated in this field, and you’ll suck, I met developers with big fat years of experience but they are outdated since 5 years and they can’t go with new technologies anymore, ask any doctor or lawyer and he’ll tell you this craft is about leaning and learning and gaining knowledge.</p>
<p>Learning development is separated into two parts:</p>
<ol>
<li>Dealing with human.
<li>Dealing with computer. </li>
</ol>
<h1>Dealing with human</h1>
<p>Dealing with human like dealing with client, don’t tell me I just want to code dude, no sometime if not all of the time you have to deal with the clients, think of it as you have your own company you’re entrepreneur now, Do you want to write code only? or you want to create success product by gathering the right requirements from clients and work on them, and then deliver this product, How will you do this if you want to write code only? </p>
<p>Dealing with human is dealing with team, crap again dude I want to put my headphones listen to music, go to the zone, and write code, nah good developers are good team player, to help your team-mate in the project, raise flag when you have a problem, or peer programming, you must have dealing with humans skill. </p>
<p>You’ll learn these skills during your work, I don’t have a screen cast, video training, or book…oh wait wait actually I know some books taking about this:</p>
<p><a href="http://www.amazon.com/gp/product/0932633439/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0932633439&amp;linkCode=as2&amp;tag=monsblo08-20">Peopleware: Productive Projects and Teams (Second Edition)</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=0932633439" width="1" height="1"> </p>
<p><img style="border-top-style: none !important; border-left-style: none !important; border-bottom-style: none !important; border-right-style: none !important; margin: 0px" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=1449302440" width="1" height="1">&nbsp;<img style="border-top-style: none !important; border-left-style: none !important; border-bottom-style: none !important; border-right-style: none !important; margin: 0px" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=0932633439" width="1" height="1"><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/1451377.jpg"><img title="1451377" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="1451377" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/1451377_thumb.jpg" width="158" height="240"></a></p>
<p><a href="http://www.amazon.com/gp/product/1449302440/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1449302440&amp;linkCode=as2&amp;tag=monsblo08-20">Team Geek: A Software Developer&#8217;s Guide to Working Well with Others</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=1449302440" width="1" height="1"> </p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51N8dmGcllL.jpg"><img title="51N8dmGcllL" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="51N8dmGcllL" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51N8dmGcllL_thumb.jpg" width="157" height="240"></a></p>
<h1>Dealing with computer:</h1>
<p>Dealing with computer is programming, In my opinion programming learning is in two stages, first learn how to code, and second leaning&nbsp; how to write code right or how to produce clean code. You’ll learn well if you learn from your mistakes,&nbsp; personally I learnt from my mistakes, every time I made a mistake I was very sad and in the beginning I made a lot of silly mistakes, please be passionate, never give up, keep going, and learn from it, I know it’s so hard in the beginning but you’ll love what you’re doing.</p>
<h1>Craftsmanship:</h1>
<blockquote><p><b>Software craftsmanship</b> is an approach to software development that emphasizes the coding skills of the software developers themselves. It is a response by software developers to the perceived ills of the mainstream software industry, including the prioritization of financial concerns over developer accountability.</p>
<p><a href="http://en.wikipedia.org/wiki/Software_craftsmanship" target="_blank">wikipedia</a></p>
</blockquote>
<p>In Clean Code book Martin Bob aka Uncle Bob wrote craftsmanship is separated into two parts Knowledge and Experience. Knowledge is the learn how to, and Experience is using knowledge to build something, so learn and practice by doing something, if you can’t build something with what you just learn you can build something as side project, <a href="https://speakerdeck.com/sachag/side-projects" target="_blank">this slides</a> encourage me to do some side projects</p>
<p>&nbsp;</p>
<p><script async class="speakerdeck-embed" data-id="508b4413c21140000200a7b7" data-ratio="1.33333333333333" src="//speakerdeck.com/assets/embed.js"></script><br />
<h1>Learning Material:</h1>
<p>This list of materials where you can learn something some are free and some are paid, so feel free to add yours in comments and give me your feedback about them.</p>
<h2>Video Training website:</h2>
<ul>
<li><a href="http://www.pluralsight.com/training" target="_blank">Pluralsight</a>
<li><a href="https://peepcode.com/" target="_blank">PeepCode</a>
<li><a href="http://tekpub.com/" target="_blank">TekPub</a>
<li><a href="https://www.udemy.com" target="_blank">Udemy</a>
<li><a href="http://www.codeschool.com/" target="_blank">CodeSchool</a>
<li><a href="http://www.campusmvp.net/" target="_blank">campusMVP</a> </li>
</ul>
<h2>Interactive Course:</h2>
<ul>
<li><a href="http://www.codecademy.com/" target="_blank">Code Academy</a>
<li><a href="http://rubymonk.com/" target="_blank">RubyMonk</a>
<li><a href="http://code.he.net/" target="_blank">Code Hurricane Electric</a> </li>
</ul>
<h2>Books:</h2>
<p>Books for developers are like water for fish, you need to read, read, and read. Technology focused books like ASP.NET books there are many of them in market but make sure you pick nice ones first, personally I search for a book using Amazon read reviews and boom I pick on and read it. There are books I recommended but it’s not technology focused it focus in making you better developer:</p>
<h3>Recommended Books:</h3>
<p><a href="http://www.amazon.com/gp/product/B0050JLC9Y/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B0050JLC9Y&amp;linkCode=as2&amp;tag=monsblo08-20">The Clean Coder: A Code of Conduct for Professional Programmers (Robert C. Martin Series)</a></p>
<p>&nbsp;<a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/0000.L.jpg"><img title="0000.L" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="0000.L" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/0000.L_thumb.jpg" width="185" height="240"></a><img style="border-top-style: none !important; border-left-style: none !important; border-bottom-style: none !important; border-right-style: none !important; margin: 0px" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B0050JLC9Y" width="1" height="1"></p>
<p><a href="http://www.amazon.com/gp/product/B001GSTOAM/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B001GSTOAM&amp;linkCode=as2&amp;tag=monsblo08-20">Clean Code: A Handbook of Agile Software Craftsmanship</a><img style="border-top-style: none !important; border-left-style: none !important; border-bottom-style: none !important; border-right-style: none !important; margin: 0px" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B001GSTOAM" width="1" height="1"></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/0132350882.jpg"><img title="0132350882" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="0132350882" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/0132350882_thumb.jpg" width="181" height="240"></a><img style="border-top-style: none !important; border-left-style: none !important; border-bottom-style: none !important; border-right-style: none !important; margin: 0px" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B001GSTOAM" width="1" height="1"></p>
<p><a href="http://www.amazon.com/gp/product/B000SEIBB8/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B000SEIBB8&amp;linkCode=as2&amp;tag=monsblo08-20">Design Patterns: Elements of Reusable Object-Oriented Software</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B000SEIBB8" width="1" height="1"></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51Q-RLSadrL.jpg"><img title="51Q-RLSadrL" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="51Q-RLSadrL" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51Q-RLSadrL_thumb.jpg" width="183" height="240"></a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B000SEIBB8" width="1" height="1"></p>
<p><a href="http://www.amazon.com/gp/product/B000SEGEKI/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B000SEGEKI&amp;linkCode=as2&amp;tag=monsblo08-20">The Pragmatic Programmer: From Journeyman to Master</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B000SEGEKI" width="1" height="1"></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/41F1cZImneL.jpg"><img title="41F1cZImneL" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="41F1cZImneL" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/41F1cZImneL_thumb.jpg" width="191" height="240"></a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B000SEGEKI" width="1" height="1"></p>
<p><a href="http://www.amazon.com/gp/product/B004OR1XGK/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B004OR1XGK&amp;linkCode=as2&amp;tag=monsblo08-20">Code Complete</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B004OR1XGK" width="1" height="1"></p>
<p><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B004OR1XGK" width="1" height="1"><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51nWkLCu1SL.jpg"><img title="51nWkLCu1SL" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="51nWkLCu1SL" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51nWkLCu1SL_thumb.jpg" width="197" height="240"></a></p>
<p><a href="http://www.amazon.com/gp/product/B008HUMTO0/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B008HUMTO0&amp;linkCode=as2&amp;tag=monsblo08-20">Effective Programming: More Than Writing Code</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B008HUMTO0" width="1" height="1"></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51ysOldcmqL.jpg"><img title="51ysOldcmqL" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="51ysOldcmqL" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/51ysOldcmqL_thumb.jpg" width="184" height="240"></a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B008HUMTO0" width="1" height="1"></p>
<p><a href="http://www.amazon.com/gp/product/B00AYQNR5U/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B00AYQNR5U&amp;linkCode=as2&amp;tag=monsblo08-20">The Passionate Programmer: Creating a Remarkable Career in Software Development (Pragmatic Life)</a><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B00AYQNR5U" width="1" height="1"></p>
<p><img style="border-top: medium none; border-right: medium none; border-bottom: medium none; margin: 0px; border-left: medium none" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=monsblo08-20&amp;l=as2&amp;o=1&amp;a=B00AYQNR5U" width="1" height="1"><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/04/5194SMyRiL.jpg"><img title="5194SMyRi L" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="5194SMyRi L" src="http://www.emadmokhtar.com/wp-content/uploads/2013/04/5194SMyRiL_thumb.jpg" width="160" height="240"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2013/04/how-do-i-learn/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Storing password in plain text, you&#8217;re doing it wrong</title>
		<link>http://www.emadmokhtar.com/2013/03/storing-password-in-plain-text-youre-doing-it-wrong/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=storing-password-in-plain-text-youre-doing-it-wrong</link>
		<comments>http://www.emadmokhtar.com/2013/03/storing-password-in-plain-text-youre-doing-it-wrong/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 13:41:09 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[#security #dotNet #Csharp]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=968</guid>
		<description><![CDATA[If you’re software developer then there is big chance you’ll implement user login feature, and you must store the username and password in your system. Most of developers stored these precious information in database as plain text, yes we did&#8230; ]]></description>
				<content:encoded><![CDATA[<p><img title="Hacking for password&#10;&#10;" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 5px; display: inline; border-top-width: 0px" border="0" alt="Hacking for password&#10;&#10;" align="right" src="http://www.emadmokhtar.com/wp-content/uploads/2013/03/114166encryption.jpg" width="425" height="282" /> If you’re software developer then there is big chance you’ll implement user login feature, and you must store the username and password in your system. Most of developers stored these precious information in database as plain text, yes we did include myself I was doing it wrong, and if you’re doing it please stop and read this article to know how to do it right and being awesome.</p>
<p>Username, Password, or Pin codes these are precious information, and if hacker or even internal employee stole the database he can do whatever he wants with your users information. So How to keep these information safe? The answer is hashing it.</p>
<p>Why I was not doing that? I was lazy and every time I googled/binged/searched about this, I found many complex How-To articles, but last week I finally found something simple and it’s the reason I’m writing this article.</p>
<h1>What is hashing?</h1>
<p>Hashing is encoding string &quot;message” to hash value and you can’t reproduce the original string “message” from hash value, so it’s one way cryptographic algorithm, <a href="http://stackoverflow.com/questions/326699/difference-between-hashing-a-password-and-encrypting-it" target="_blank">it’s different than encryption</a> that it’s&#160; two way cryptographic algorithm.</p>
<h1>How to Hash password?</h1>
<p>As I mentioned above I found many articles about how-to hash password but most of them are very complex and I believe in work smart not hard, I found <a href="http://msdn.microsoft.com/en-us/library/system.web.helpers(v=vs.99).aspx" target="_blank">System.Web.Helpers</a> <em>Namespace</em> that has <a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto(v=vs.99).aspx" target="_blank">Crypto</a> <em>Class</em> that has many hashing helpers. I play with it and try to learn how to hash a password.</p>
<h2>Flow:</h2>
<p>Now let’s understand the flow and then check how to implement it in code. First to save password in database you must hash it using one of hashing algorithm and store the hashes password into database.</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/03/StoreHashedPassword.png"><img title="StoreHashedPassword" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="StoreHashedPassword" src="http://www.emadmokhtar.com/wp-content/uploads/2013/03/StoreHashedPassword_thumb.png" width="640" height="90" /></a> </p>
<p>Second to check the user password in login, you should hash the password user input and compare the two hashed passwords (user input &amp; stored in database).</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/03/RetreiveHashedPassword.png"><img title="RetreiveHashedPassword" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="RetreiveHashedPassword" src="http://www.emadmokhtar.com/wp-content/uploads/2013/03/RetreiveHashedPassword_thumb.png" width="640" height="221" /></a> </p>
<h2>Code:</h2>
<p>I’ll show you how to hash user’s password and check the password he’ll enter when login to your system. Like I said above I’ll user <em><a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto(v=vs.99).aspx" target="_blank">System.Web.Helpers.Crypto</a></em> <em>Class</em>, this class has 2 m<em>ethods</em> <em><a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto.hashpassword(v=vs.99).aspx" target="_blank">HashPassword</a></em> and <a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto.verifyhashedpassword(v=vs.99).aspx" target="_blank"><em>VerifyHashedPassword</em></a> we’ll use them<em>. </em>we’ll write the code in Unit Tests so no need for Console Application and wait for Command Prompt to run, you’ll just write your code test it and you’ll get results in test results quickly, so let’s get our hand dirty:</p>
<h3>Hash:</h3>
<p>What you need to do is to pass the user input password to <em>HashPassword() Method</em> and you’ll get the hashed password.</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span> plainPassword = <span class="str">&quot;P@12345566&quot;</span>;</pre>
<pre><span class="lnum">   2:  </span> hashedPassword = Crypto.HashPassword(plainPassword);</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>Compare:</h3>
<p>We can verify the password by passing the hashed password and the plain password and<em> VerifyHashedPassword() Method</em> will return true if it’s verified or false if it’s not.</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>Assert.AreEqual(<span class="kwrd">true</span>, Crypto.VerifyHashedPassword(hashedPassword,plainPassword));</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>Complete Code:</h3>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> test_hashing_password()</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    <span class="kwrd">string</span> plainPassword;</pre>
<pre class="alt"><span class="lnum">   5:  </span>    <span class="kwrd">string</span> hashedPassword;</pre>
<pre><span class="lnum">   6:  </span>           </pre>
<pre class="alt"><span class="lnum">   7:  </span>    plainPassword = <span class="str">&quot;P@12345566&quot;</span>;</pre>
<pre><span class="lnum">   8:  </span>    hashedPassword = Crypto.HashPassword(plainPassword);</pre>
<pre class="alt"><span class="lnum">   9:  </span>&#160;</pre>
<pre><span class="lnum">  10:  </span>    Assert.AreEqual(<span class="kwrd">true</span>, Crypto.VerifyHashedPassword(hashedPassword,plainPassword));</pre>
<pre class="alt"><span class="lnum">  11:  </span>&#160;</pre>
<pre><span class="lnum">  12:  </span>}</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><em>Note: I’m using <a href="http://www.nunit.org/" target="_blank">NUnit</a> as my Unit Test Framework and <a href="http://www.jetbrains.com/resharper/" target="_blank">Resharper</a> as my Test Runner.</em></p>
</p>
<h1>Yet better Hashing:</h1>
</p>
</p>
<p>Even after hashing passwords you aren’t safe from hacking and hackers, hackers can use <a href="http://en.wikipedia.org/wiki/Rainbow_table" target="_blank">rainbow table</a> to attack your system. The good news is you can increase the security of your hashing by adding salt, let’s see how we can do this:</p>
<h2>Flow</h2>
<p>Save the password looks like the same flow but this time we’ll use <a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto.generatesalt(v=vs.99).aspx" target="_blank"><em>GenerateSalt</em></a><em> Method</em> in <a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.crypto(v=vs.99).aspx" target="_blank"><em>System.Web.Helpers</em></a><em> Class</em> to generate random salt that will be added to the password and store it to database with the hashed password.</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/03/YetBetterStoreHashingPassword.png"><img title="YetBetterStoreHashingPassword" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="YetBetterStoreHashingPassword" src="http://www.emadmokhtar.com/wp-content/uploads/2013/03/YetBetterStoreHashingPassword_thumb.png" width="640" height="164" /></a> </p>
<p>Retrieving and comparing user input password and the one stored in database is as before but you need to retrieve both the hashed password and salt from database, add salt to plain password, hash the produced string, then compare it with the hashed password that retrieved from database. </p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/03/YetBetterRetreivePassword.png"><img title="YetBetterRetreivePassword" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="YetBetterRetreivePassword" src="http://www.emadmokhtar.com/wp-content/uploads/2013/03/YetBetterRetreivePassword_thumb.png" width="640" height="285" /></a> </p>
<h2>Code:</h2>
<h3>Hash:</h3>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>plainPassword = <span class="str">&quot;P@12345566&quot;</span>;</pre>
<pre><span class="lnum">   2:  </span>salt = Crypto.GenerateSalt();</pre>
<pre class="alt"><span class="lnum">   3:  </span>passwordSaltCombination = plainPassword + salt;</pre>
<pre><span class="lnum">   4:  </span>hashedPassword = Crypto.HashPassword(passwordSaltCombination);</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>Compare:</h3>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>Assert.AreEqual(<span class="kwrd">true</span>, Crypto.VerifyHashedPassword(hashedPassword, passwordSaltCombination));</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h3>Complete Code:</h3>
</p>
</p>
</p>
</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span>[Test]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> test_hasing_password_with_salt()</pre>
<pre><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    <span class="kwrd">string</span> plainPassword;</pre>
<pre><span class="lnum">   5:  </span>    <span class="kwrd">string</span> hashedPassword;</pre>
<pre><span class="lnum">   6:  </span>    <span class="kwrd">string</span> salt;</pre>
<pre><span class="lnum">   7:  </span>    <span class="kwrd">string</span> passwordSaltCombination;</pre>
<pre><span class="lnum">   8:  </span>&#160;</pre>
<pre><span class="lnum">   9:  </span>    plainPassword = <span class="str">&quot;P@12345566&quot;</span>;</pre>
<pre><span class="lnum">  10:  </span>    salt = Crypto.GenerateSalt();</pre>
<pre><span class="lnum">  11:  </span>    passwordSaltCombination = plainPassword + salt;</pre>
<pre><span class="lnum">  12:  </span>    hashedPassword = Crypto.HashPassword(passwordSaltCombination);</pre>
<pre><span class="lnum">  13:  </span>&#160;</pre>
<pre><span class="lnum">  14:  </span>    Assert.AreEqual(<span class="kwrd">true</span>, Crypto.VerifyHashedPassword(hashedPassword, passwordSaltCombination));</pre>
<pre><span class="lnum">  15:  </span>&#160;</pre>
<pre><span class="lnum">  16:  </span>}</pre>
</div>
<p>As you can see it’s simple procedure so please use it and stop saving plain password in your database.</p>
<p>I encourage you to read Jeff Atwood’s article <a href="http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html">You&#8217;re Probably Storing Passwords Incorrectly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2013/03/storing-password-in-plain-text-youre-doing-it-wrong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamics AX 2012 On-Demand Events</title>
		<link>http://www.emadmokhtar.com/2013/02/dynamics-ax-2012-on-demand-events/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dynamics-ax-2012-on-demand-events</link>
		<comments>http://www.emadmokhtar.com/2013/02/dynamics-ax-2012-on-demand-events/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 05:52:16 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[Dynamics Ax]]></category>
		<category><![CDATA[AX2012]]></category>
		<category><![CDATA[DYNAX]]></category>
		<category><![CDATA[MDAX]]></category>
		<category><![CDATA[MSDYNAX]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=956</guid>
		<description><![CDATA[Mr. Hatem Taha (Partner Account Manager – MBS in Microsoft Kuwait) emailed me a list of on demand event for Microsoft Dynamics AX 2012, and he asked me to share it with you. Note: You must be associated to MBS&#8230; ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.linkedin.com/profile/view?id=79033396&amp;authType=NAME_SEARCH&amp;authToken=G7Eq&amp;locale=en_US&amp;srchid=e55557ca-1f42-425c-a928-eab4e00fe4d4-0&amp;srchindex=1&amp;srchtotal=2&amp;goback=%2Efps_PBCK_*1_Hatem_Taha_*1_*1_*1_*1_*2_*1_Y_*1_*1_*1_false_1_R_*1_*51_*1_*51_true_*1_kw%3A0_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2&amp;pvs=ps&amp;trk=pp_profile_name_link" target="_blank">Mr. Hatem Taha</a> (<em>Partner Account Manager – MBS in Microsoft Kuwait</em>) emailed me a list of on demand event for Microsoft Dynamics AX 2012, and he asked me to share it with you.</p>
<p><strong>Note:</strong> You must be associated to MBS (Microsoft Business Solutions) partner in order to access these links.</p>
<h2>Links:</h2>
<table cellspacing="0" cellpadding="0" width="701" border="1">
<tbody>
<tr>
<td width="178">
<p><b>TITLE</b></p>
</td>
<td width="141">
<p><b>Modality</b></p>
</td>
<td width="138">
<p><b>STATUS</b></p>
</td>
<td width="139">
<p><b>EST Release Date</b></p>
</td>
<td width="103">
<p><b>RELEASE MANAGER</b></p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 Workshop: Security</b></p>
</td>
<td width="141">
<p>On-Demand Video</p>
</td>
<td width="138">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=832647">Link to course on PLC</a></p>
</td>
<td width="139">
<p>New Release</p>
</td>
<td width="104">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 Workshop: Retail</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=830334">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="105">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Lean Manufacturing New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=833249">Link to course on PLC</a></p>
</td>
<td width="138">
<p>New Release</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Services and GAB New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=826411">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Financial Budgeting New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=827850">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Tech Domain and Development New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=830948">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Payroll Introduction</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=830946">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Human Resources New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=831433">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Microsoft Dynamics AX 2012 R2 Reporting and BI New Features</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=831434">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
<tr>
<td width="177">
<p><b>Partner Technical Services: Product Release Training Microsoft Dynamics AX 2012 Development New Features (Part 6)</b></p>
</td>
<td width="140">
<p>On-Demand Video</p>
</td>
<td width="137">
<p><a href="https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&amp;ActivityId=830949">Link to course on PLC</a></p>
</td>
<td width="138">
<p>Released</p>
</td>
<td width="106">
<p>Melissa Maasjo</p>
</td>
</tr>
</tbody>
</table>
<p>Happy watching.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2013/02/dynamics-ax-2012-on-demand-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to be Microsoft Dynamics AX Developer</title>
		<link>http://www.emadmokhtar.com/2013/02/how-to-be-microsoft-dynamics-ax-developer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-be-microsoft-dynamics-ax-developer</link>
		<comments>http://www.emadmokhtar.com/2013/02/how-to-be-microsoft-dynamics-ax-developer/#comments</comments>
		<pubDate>Mon, 18 Feb 2013 07:52:09 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[Dynamics Ax]]></category>
		<category><![CDATA[AX2009]]></category>
		<category><![CDATA[AX2012]]></category>
		<category><![CDATA[DYNAX]]></category>
		<category><![CDATA[MDAX]]></category>
		<category><![CDATA[MSDYNAX]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=955</guid>
		<description><![CDATA[Do you want to be Microsoft Dynamics AX Developer? I assume you are. Learn how to develop on Microsoft Dynamics AX is not as easy as it seems, it is not as easy as learning to developer using other platforms&#8230; ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/comfort_550.jpg"><img title="comfort_550" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; float: none; margin-left: auto; display: block; border-top-width: 0px; margin-right: auto" border="0" alt="comfort_550" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/comfort_550_thumb.jpg" width="550" height="366" /></a> </p>
<p>Do you want to be Microsoft Dynamics AX Developer? I assume you are. Learn how to develop on Microsoft Dynamics AX is not as easy as it seems, it is not as easy as learning to developer using other platforms like Microsoft SharePoint. The material provided from Microsoft is not that one will give you the full picture about the platform, it will give you only the guidelines and you have to go and search and search and search and search. It took me 2 full years to know what I knew now, it is not much but I can do many things not included in the documentations.</p>
<p>So I decided to write this article to make it short on new developers whom want to learn about developing with Microsoft Dynamics AX and even help whom already Microsoft Dynamics AX developers.</p>
<h1>The Platform:</h1>
<h2>Programming Language:</h2>
<p>Microsoft Dynamics AX is built with its programming language called <a href="http://en.wikipedia.org/wiki/X%2B%2B#MorphX_and_X.2B.2B" target="_blank"><strong>X++</strong></a>, it is like C++, C#, or Java, it is Object Oriented, if you know one of these languages you will be familiar with X++. </p>
<h2>IDE (Integrated Development Environment) :</h2>
<p>Microsoft Dynamics AX has its own IDE called <a href="http://en.wikipedia.org/wiki/MorphX#MorphX_and_X.2B.2B" target="_blank">MorphX</a>, you will use it during all your development tasks, it is very easy and support drag and drop to make developer life easier but from my opinion the only cons is it is not supporting multi-monitor, you need to work in one window in one monitor, it is not like Visual Studio you can drag the Toolbox bar and drop it to other monitor.</p>
<h2>The Journey:</h2>
<p>I started by reading the <a href="https://mbs.microsoft.com/CMS/Templates/site/DLPP.aspx?NRMODE=Published&amp;NRNODEGUID=%7bC4BA7F45-1232-4A4C-906D-E37D7305B2CE%7d&amp;NRORIGINALURL=%2fpartnersource%2fcommunities%2ftraining%2ftrainingmaterials%2fstudent&amp;NRCACHEHINT=Guest" target="_blank">Microsoft Student Training Document</a> you need to have access to Microsoft Partner Source or Customer Source, then start to develop and found out these documents is not enough and I need to learn something more, I started to Googling or Binging and land on small parts that are helping but you need to add yours to make it full solution, for example I need to create a Sales Order and Sales Line from the code, I found sample code to create one using job (Job in AX is small runnable code) not how to use it inside a form whether to implement it in Class, Form, or Table, and if you will implement it in Form in which level DataSource or Design, I was confused and none on web can help me in setting things together till I found this great free book called <a href="http://www.steenandreasen.com/index.php?page=morphx-it" target="_blank">MorhpX IT</a> it was written for AX 4.0 but it still have useful information works with AX 2012 R2 I encourage you to read it after reading Student Training Documents, I really got the full picture of the platform and now I feel like I’m understand what I’m doing.</p>
<h1>Materials:</h1>
<h2>Books:</h2>
<p>Inside Microsoft Dynamics AX 2012 </p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/lrg.jpg"><img title="lrg" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin-left: 0px; display: inline; border-top-width: 0px; margin-right: 0px" border="0" alt="lrg" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/lrg_thumb.jpg" width="200" height="244" /></a> </p>
<p><a href="http://www.packtpub.com/microsoft-dynamics-ax-2012-development-cookbook/book" target="_blank">Microsoft Dynamics AX 2012 Development Cookbook</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/4644EN_MicrosoftDynamicsAX2012DevelopmentCookbook_Low.jpg"><img title="4644EN_Microsoft Dynamics AX 2012 Development Cookbook_Low" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="4644EN_Microsoft Dynamics AX 2012 Development Cookbook_Low" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/4644EN_MicrosoftDynamicsAX2012DevelopmentCookbook_Low_thumb.jpg" width="198" height="244" /></a> </p>
<p><a href="http://www.packtpub.com/microsoft-dynamics-ax-2012-services/book" target="_blank">Microsoft Dynamics AX 2012 Services</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7546EN_cov.jpg"><img title="7546EN_cov" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="7546EN_cov" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7546EN_cov_thumb.jpg" width="199" height="244" /></a> </p>
<p><a href="http://www.packtpub.com/microsoft-dynamics-ax-2012-security/book" target="_blank">Microsoft Dynamics AX 2012 Security How-To</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7508ENcov.jpg"><img title="7508ENcov" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="7508ENcov" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7508ENcov_thumb.jpg" width="199" height="244" /></a> </p>
<p><a href="http://shop.oreilly.com/product/9780735626454.do" target="_blank">Inside Microsoft Dynamics® AX 2009</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/lrg1.jpg"><img title="lrg (1)" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="lrg (1)" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/lrg1_thumb.jpg" width="201" height="244" /></a> </p>
<p><a href="http://www.packtpub.com/microsoft-dynamics-ax-2009-programming/book" target="_blank">Microsoft Dynamics AX 2009 Programming: Getting Started</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7306_MockupCover.jpg"><img title="7306_MockupCover" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="7306_MockupCover" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/7306_MockupCover_thumb.jpg" width="198" height="244" /></a> </p>
<p><a href="http://www.packtpub.com/microsoft-dynamics-ax-2009-development-cookbook/book" target="_blank">Microsoft Dynamics AX 2009 Development Cookbook</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/9423_MockupCover.jpg"><img title="9423_MockupCover" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="9423_MockupCover" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/9423_MockupCover_thumb.jpg" width="198" height="244" /></a> </p>
<p><a href="http://www.steenandreasen.com/index.php?page=morphx-it" target="_blank">MorphX IT</a></p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2013/02/product_thumbnail.jpg"><img title="product_thumbnail" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="product_thumbnail" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/product_thumbnail_thumb.jpg" width="174" height="244" /></a> </p>
<h2>Blogs:</h2>
<p><a href="http://daxdilip.blogspot.com/" target="_blank">Dilip&#8217;s blog on DYNAMICS AX</a></p>
<p><a href="http://kashperuk.blogspot.com/" target="_blank">Dynamics AX tools and tutorials</a></p>
<p><a href="http://fedotenko.info/">Investigating DAX</a></p>
<p><a href="http://dynamicsaxposed.wordpress.com/">Dynamics Ax workshop</a></p>
<p><a href="https://msdax.wordpress.com/">Amir&#8217;s Microsoft Dynamics AX space</a></p>
<p><a href="http://daxmusings.codecrib.com/" target="_blank">Dynamics Ax Musings</a></p>
<h2>Community:</h2>
<p><a href="https://community.dynamics.com/product/ax/default.aspx" target="_blank">Microsoft Dynamics AX community</a></p>
<p><a href="http://www.axug.com/" target="_blank">AX User Group</a></p>
<p><a href="http://dynamicsuser.net/" target="_blank">Dynamics User Group</a></p>
<p><a href="http://stackoverflow.com/" target="_blank">Stack Overflow</a> tags: <a href="http://stackoverflow.com/questions/tagged/dynamics-ax-2009" target="_blank">dynamics-ax-2009</a> <a href="http://stackoverflow.com/questions/tagged/dynamics-ax-2012" target="_blank">dynamics-ax-2012</a> <a href="http://stackoverflow.com/questions/tagged/x%2b%2b" target="_blank">x++</a> <a href="http://stackoverflow.com/questions/tagged/dynamics-ax" target="_blank">dynamics-ax</a>&#160;<a href="http://stackoverflow.com/questions/tagged/axapta" target="_blank">Axapta</a></p>
</p>
</p>
</p>
</p>
<h1>The End</h1>
<p>At the end I hope this article helps you and start the journey of learning developing on Dynamics AX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2013/02/how-to-be-microsoft-dynamics-ax-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create Metro UI ASP.NET Application</title>
		<link>http://www.emadmokhtar.com/2013/02/how-to-create-metro-ui-asp-net-application/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-metro-ui-asp-net-application</link>
		<comments>http://www.emadmokhtar.com/2013/02/how-to-create-metro-ui-asp-net-application/#comments</comments>
		<pubDate>Sat, 02 Feb 2013 14:31:50 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspnet]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[icons]]></category>
		<category><![CDATA[metroui]]></category>
		<category><![CDATA[modernui]]></category>
		<category><![CDATA[webforms]]></category>
		<category><![CDATA[win8]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=934</guid>
		<description><![CDATA[If you’re ASP.NET developer, you’re concern about the User Interface/Design of your application and you notice Metro/Modern UI is neat and great UI, but How I can make my ASP.NET application look like Windows 8 application? Can I do that?&#8230; ]]></description>
				<content:encoded><![CDATA[<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Microsoft-METRO-UI-Description.svg" border="0" alt="Microsoft-METRO-UI-Description.svg" align="right" src="http://www.emadmokhtar.com/wp-content/uploads/2013/02/Microsoft-METRO-UI-Description.svg_.png" width="244" height="149" /></p>
<p>If you’re ASP.NET developer, you’re concern about the User Interface/Design of your application and you notice Metro/Modern UI is neat and great UI, but How I can make my ASP.NET application look like Windows 8 application? Can I do that? The answer is Yes you can, there’re bunch of (free/paid) tools that will help in make your ASP.NET application looks like Windows 8 application.</p>
<p>Before listing the tools, let’s see Why Metro/Modern UI is neat? and Why Microsoft choose it to be its UI cross all its platforms? Microsoft Modern/Metro UI inspired by public transportation signs and it’s a typography design which focus on the content by implement typography more than graphics. </p>
<h3>My Experience</h3>
<p>Personally I didn’t use Windows 8 yet, I’ve tired it but I didn’t use it as my daily OS. Last week I bought <a href="http://www.nokia.com/mea-en/products/phone/lumia920" target="_blank">Nokia Lumia 920</a> and What made my mind to buy it and go for Windows Phone after using Android for 2 years? It’s the UI and UX, yes Microsoft made it this time. Me and my wife were shopping, we went to try this phone and she said wow this UI and UX are great (she&#8217;s an Apple fan) and I agree with he. I’m using the phone for a week only and I love it.</p>
<h3></h3>
<h3>Modern UI or Metro UI</h3>
<p>If you noticed I’m using Metro/Modern UI not Metro only, because Microsoft forced to change the name of its new UI to Modern because of some legal issues and copyrights, it’s rumor but the true is Microsoft stop calling it Metro and mention it as “Microsoft design language” and some folks on the internet call it Modern UI.</p>
<h3></h3>
<h3>The List (Tools)</h3>
<p>Your ASP.NET will have a great UI if you add Metro UI to it, so let’s list the tools:</p>
<ul>
<li><strong>CSS/JavaScript:</strong>
<ul>
<li><a href="http://metroui.org.ua/" target="_blank">Metro UI CSS</a> (free): It’s CSS framework helps you create most of the things in Metro/Modern UI components like live tiles, toggles, textboxes, buttons, and much much more, it has its grid system and it’s not based Twitter Bootstrap. </li>
<li><a href="http://aozora.github.com/bootmetro/" target="_blank">Bootmetro</a> (free): It’s based on Twitter Bootstrap so you still have features of bootstrap and has some of Metro UI components like hub/tile. action buttons, notifications, list view. etc.. </li>
<li><a href="http://talkslab.github.com/metro-bootstrap/index.html" target="_blank">Metro-bootstrap</a> (free): It’s also based on Twitter Bootstrap but it’s lack of many Metro/Modern UI components. </li>
</ul>
</li>
<li><strong>Icons:</strong>
<ul>
<li><a href="http://www.syncfusion.com/downloads/metrostudio" target="_blank">Syncfusion Metro Studio</a> (free): It’s free&#160; desktop application that have more than 1700 icons you’ll need when building Metro/Modern application, the great thing about this tool is you can arrange icons in projects, export icons to many extension or ever <a href="http://www.w3schools.com/css/css_image_sprites.asp" target="_blank">CSS sprites</a>, and resize icons. </li>
<li><a href="http://modernuiicons.com/" target="_blank">MetroUIIcons.com</a> (free): It’s a website contains more than 800 handcrafted Metro UI icons, the create thing about this website that you can contribute because it’s open source and hosted on <a href="https://github.com/Templarian/WindowsIcons/" target="_blank">GitHub</a> plus you can make a request for an Icon. </li>
</ul>
</li>
<li><strong>ASP.NET Control</strong>:
<ul>
<li><a href="http://www.telerik.com/products/aspnet-ajax.aspx" target="_blank">Telerik ASP.NET Ajax RadControls</a> (paid): Telerik is the one of the best companies that provide .NET tools/controls to .NET developers, it has RadControls for ASP.NET WebForms, one of the best feature of RadControls is the style, Telerik provides wide rang of styles with RadControls so developers can use them out of the box. Two of RadControls styles are Metro which looks like Metro/Modern UI and Metro Touch which is a touch enabled version of Metro/Modern UI. </li>
</ul>
</li>
</ul>
<h3>What I’m using</h3>
<p>Personally I’m using Metro UI CSS, Syncfusion Metro Studio, and Telerik ASP.NET Ajax RadContorls, it’s working fine together not perfect because there’re some CSS conflicts between Metro UI CSS and Telerik ASP.NET Ajax RadContorls, but in the other hand it’s working, nowadays I’m working on an ASP.NER WebForms application with those 3 tools to make it looks like Windows 8 application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2013/02/how-to-create-metro-ui-asp-net-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fix MaxLength property for ASP.NET Multiline Textbox</title>
		<link>http://www.emadmokhtar.com/2012/11/fix-maxlength-property-for-asp-net-multiline-textbox/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fix-maxlength-property-for-asp-net-multiline-textbox</link>
		<comments>http://www.emadmokhtar.com/2012/11/fix-maxlength-property-for-asp-net-multiline-textbox/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 07:54:10 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[aspnet]]></category>
		<category><![CDATA[webforms]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=930</guid>
		<description><![CDATA[If you try to change the TextMode property of ASP.NET TextBox control to Multiline and set the MaxLength property it’ll not work and user can insert as much characters as he/she want. WHY? Because when you put TextBox in your&#8230; ]]></description>
				<content:encoded><![CDATA[<p>If you try to change the TextMode property of ASP.NET TextBox control to Multiline and set the MaxLength property it’ll not work and user can insert as much characters as he/she want. WHY? Because when you put TextBox in your WebForm it’ll be rendered to HTML <em>&lt;input&gt;</em> tag but when you set the TextMode to multiline it’ll be rendered to <em>&lt;textarea&gt;</em> tag, and MaxLength attribute is in <em>&lt;input&gt;</em> but it’s not for <em>&lt;textarea&gt;</em>.</p>
<p>So dude How can I solve this issue?</p>
<p>From my opinion it’s better to solve this by using JavaScript function than using RegularExpressionValidator, so let’s write the JavaScript function and call it in onKeyPress TextBox client event.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:246112b8-c17a-4cb5-92ce-8f31e8e69d6f" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">JavaScript function</div>
<div style="background: #ddd; overflow: auto">
<ol start="1" style="background: #22282a; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">function</span><span style="color:#f1f2f3"> textboxMultilineMaxNumber(txt, maxLen) {</span></li>
<li style="background: #161c1e">&nbsp;</li>
<li><span style="color:#f1f2f3">            </span><span style="color:#93c763">if</span><span style="color:#f1f2f3"> (txt.value.length &gt; (maxLen &#8211; </span><span style="color:#ffcd22">1</span><span style="color:#f1f2f3">)) </span><span style="color:#93c763">return</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">false</span><span style="color:#f1f2f3">;</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">            </span><span style="color:#93c763">else</span><span style="color:#f1f2f3"> {</span></li>
<li><span style="color:#f1f2f3">                </span><span style="color:#93c763">return</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">true</span><span style="color:#f1f2f3">;</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">            }</span></li>
<li><span style="color:#f1f2f3">        }</span></li>
</ol></div>
</p></div>
</p></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a74685d0-fe1e-4754-9188-7572abf305bd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">MultiLine TextBox</div>
<div style="background: #ddd; overflow: auto">
<ol start="1" style="background: #22282a; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">TextBox</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">ID=</span><span style="color:#ec7600">&quot;TextBox1&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">runat=</span><span style="color:#ec7600">&quot;server&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">TextMode=</span><span style="color:#ec7600">&quot;MultiLine&quot;</span><span style="color:#f1f2f3"> </span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="background:#293134;color:#e0e2e4">onkeypress=</span><span style="color:#ec7600">&quot;return textboxMultilineMaxNumber(this,15);&quot;</span><span style="color:#f1f2f3">&gt; </span></li>
<li>    <span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">TextBox</span><span style="color:#f1f2f3">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>As you can see in line number 2 I pass TextBox and MaxLength, this will make the max number of characters user can input in the MultiLine TextBox is 15.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2012/11/fix-maxlength-property-for-asp-net-multiline-textbox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Add elegant style to ASP.NET WebForms GridView control</title>
		<link>http://www.emadmokhtar.com/2012/07/add-elegant-style-to-asp-net-webforms-gridview-controls/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-elegant-style-to-asp-net-webforms-gridview-controls</link>
		<comments>http://www.emadmokhtar.com/2012/07/add-elegant-style-to-asp-net-webforms-gridview-controls/#comments</comments>
		<pubDate>Wed, 11 Jul 2012 08:45:23 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspnet]]></category>
		<category><![CDATA[gridview]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=927</guid>
		<description><![CDATA[We are developers whom use the left side of our brains that why we suck in designing; we’ll use the already exist styles while developing ASP.NET web application, that what we’ll do if we don’t have a designer in our&#8230; ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/07/5628591299_8d5839c072.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="5628591299_8d5839c072" border="0" alt="5628591299_8d5839c072" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/5628591299_8d5839c072_thumb.jpg" width="640" height="411" /></a>We are developers whom use the left side of our brains that why we suck in designing; we’ll use the already exist styles while developing ASP.NET web application, that what we’ll do if we don’t have a designer in our team, but thanks for the CSS framework over the internet which make our like more easier.</p>
<p>Nowadays I’m playing with <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap</a> CSS framework and I find myself create very neat and awesome looking ASP.NET applications by just using the already defined CSS classes in the framework, it’s so easy and the documentation is easy to understand and readable, you can find the documentation right <a href="http://twitter.github.com/bootstrap/base-css.html" target="_blank">here</a>.</p>
<p>So let’s get into the business, the most commonly used ASP.NET Control <strong>GridView </strong>is very ugly if you don’t apply a style to it, it’ll look like an awful HTML table with bunch of rows and columns, sure you can use the ready made styles “Auto Format” created by Microsoft team, but also you can apply much better style to it, let’s find how.<a href="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0089.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAG-0089" border="0" alt="SNAG-0089" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0089_thumb.png" width="558" height="435" /></a></p>
<p>I’ll show you how to apply 2 styles to GridView:</p>
<ol>
<li>Twitter Bootstrap.</li>
<li>ASP.NET Dynamic Data.</li>
</ol>
<h3>Twitter Bootstrap:</h3>
<p>I mentioned above nowadays I’m playing with Twitter Bootstrap and I love its <a href="http://twitter.github.com/bootstrap/base-css.html#tables" target="_blank">Table style</a>, it’s very simple and neat and have many style can be used separately or make a combination of them. I love to use the full combination of them and it can be applied to the <strong>GridView </strong>by assign the <strong>CssClass</strong> property to Twitter Bootstrap CSS classes like this:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:840d632d-74dc-46f3-83c1-284e3d229b3d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; max-height: 500px; overflow: auto">
<ol style="background: #22282a; margin: 0; padding: 0 0 0 5px;">
<li><span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">GridView</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">ID=</span><span style="color:#ec7600">&quot;GridView1&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">runat=</span><span style="color:#ec7600">&quot;server&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">AutoGenerateColumns=</span><span style="color:#ec7600">&quot;False&quot;</span><span style="color:#f1f2f3"> </span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="background:#293134;color:#e0e2e4">DataSourceID=</span><span style="color:#ec7600">&quot;XmlDataSource1&quot;</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="background:#293134;color:#e0e2e4">CssClass=</span><span style="color:#ec7600">&quot;table table-striped table-bordered table-condensed&quot;</span><span style="color:#f1f2f3">&gt;</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">Columns</span><span style="color:#f1f2f3">&gt;</span></li>
<li>        <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li style="background: #161c1e">        <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li>        <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">Columns</span><span style="color:#f1f2f3">&gt;</span></li>
<li><span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">GridView</span><span style="color:#f1f2f3">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Here is the result:</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0091.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAG-0091" border="0" alt="SNAG-0091" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0091_thumb.png" width="711" height="122" /></a></p>
<p>You can use style you like you can check the Table styles and make your combination or use only one CSS class.</p>
<p>You can install Twitter Bootstrap to your solution from NuGet. Go to Tools –&gt; Library Package Manager –&gt; Manage NuGet Packages for solutions… NuGet package manager window will open, search for Twitter Bootstrap and Install it.</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0087.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAG-0087" border="0" alt="SNAG-0087" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0087_thumb.png" width="703" height="395" /></a></p>
<h3>ASP.NET Dynamic Data:</h3>
<p>One day I was checking <a href="http://msdn.microsoft.com/en-us/library/ee845452.aspx" target="_blank">ASP.NET Dynamic Data</a>, I built and started the project, and then I saw a very beautiful <strong>GridView.</strong> I start to dig in the aspx file on how ASP.NET team made this <strong>GridView</strong> beautiful like that, finally I found they are using a CSS specially made for Dynamic Data, I grab it and applied it to another demo project has a <strong>GridView </strong>and took care of the Image file used in header’s background.</p>
<p>Here is the <strong>GridView </strong>control, take a look on <strong>CssClass</strong>, <strong>RowStyle-CssClass</strong>, and <strong>HeaderStyle-CssClass</strong> properties:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2821cb40-fd9d-469a-bf5d-468de33206fe" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; overflow: auto">
<ol style="background: #22282a; margin: 0; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">GridView</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">ID=</span><span style="color:#ec7600">&quot;GridView&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">runat=</span><span style="color:#ec7600">&quot;server&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">AutoGenerateColumns=</span><span style="color:#ec7600">&quot;False&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataSourceID=</span><span style="color:#ec7600">&quot;XmlDataSource&quot;</span></li>
<li style="background: #161c1e">            <span style="color:#f1f2f3"></span><span style="background:#293134;color:#e0e2e4">CssClass=</span><span style="color:#ec7600">&quot;DDGridView&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">RowStyle-CssClass=</span><span style="color:#ec7600">&quot;td&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderStyle-CssClass=</span><span style="color:#ec7600">&quot;th&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">CellPadding=</span><span style="color:#ec7600">&quot;6&quot;</span><span style="color:#f1f2f3">&gt;</span></li>
<li>            <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">Columns</span><span style="color:#f1f2f3">&gt;</span></li>
<li style="background: #161c1e">                <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;id&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li>                <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;name&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li style="background: #161c1e">                <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">BoundField</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">DataField=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">HeaderText=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">SortExpression=</span><span style="color:#ec7600">&quot;phone&quot;</span><span style="color:#f1f2f3"> /&gt;</span></li>
<li>            <span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">Columns</span><span style="color:#f1f2f3">&gt;</span></li>
<li style="background: #161c1e">        <span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="color:#93c763">GridView</span><span style="color:#f1f2f3">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Here is the result:</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0092.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="SNAG-0092" border="0" alt="SNAG-0092" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/SNAG-0092_thumb.png" width="725" height="121" /></a></p>
<p>I’ve created a Demo project, you can download it from <a href="https://github.com/EmadMokhtar/ASPNETGridViewWithStyle" target="_blank">GitHub</a>.</p>
<p>Happy Developing Folks <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.emadmokhtar.com/wp-content/uploads/2012/07/wlEmoticon-winkingsmile.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2012/07/add-elegant-style-to-asp-net-webforms-gridview-controls/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Started PetaPoco: Create POCO and perform CRUD</title>
		<link>http://www.emadmokhtar.com/2012/05/getting-started-petapoco-create-poco-and-perform-crud/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-started-petapoco-create-poco-and-perform-crud</link>
		<comments>http://www.emadmokhtar.com/2012/05/getting-started-petapoco-create-poco-and-perform-crud/#comments</comments>
		<pubDate>Sun, 27 May 2012 07:57:53 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[DataAccess]]></category>
		<category><![CDATA[dotNet]]></category>
		<category><![CDATA[Micro-ORM]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[PetaPoco]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=910</guid>
		<description><![CDATA[I love PetaPoco and I wrote a post about which Micro-ORM is better, I picked PetaPoco and every time I want to access database I use it, it’s fast and easy, no need to setup the mapping like ORMs, but&#8230; ]]></description>
				<content:encoded><![CDATA[<p>I love PetaPoco and I wrote a <a href="http://www.emadmokhtar.com/2011/11/micro-orms-war-dapper-vs-massive-vs-petapoco/" target="_blank">post about which Micro-ORM is better</a>, I picked PetaPoco and every time I want to access database I use it, it’s fast and easy, no need to setup the mapping like ORMs, but I don’t say that Micro-ORMs are better than ORMs, in some situations you need to use an ORM. PetaPoco is better than using the old ADO.NET approach of using Connection, open it, create either DataTable or DataSet with DataAdapter, and fill them with data.</p>
<p>In this post we’ll learn How to create one <a href="http://en.wikipedia.org/wiki/POCO" target="_blank">POCO</a> and perform <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete" target="_blank">CRUD</a> on it, I’ll use the famous <a href="http://www.microsoft.com/en-us/download/details.aspx?id=23654" target="_blank">Northwind database</a> and create POCO for Customers table, let’s see how we can do it.</p>
<h2></h2>
<h2>Get PetaPoco:</h2>
<p>We need to get PetaPoco in our project and there are 2 ways:</p>
<ol>
<li>Install it from <a href="http://nuget.org/" target="_blank">NuGet</a>:
<ul>
<li>Use NuGet package manger and if you don’t have NuGet you can download it from <a href="http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c" target="_blank">here</a>. </li>
<li>In <a href="http://docs.nuget.org/docs/start-here/using-the-package-manager-console" target="_blank">NuGet package manager console</a>, write <strong>Install-Package PetaPoco.</strong> </li>
<li>If you see message “Successfully installed &#8216;PetaPoco 4.0.3&#8242;.” then you’re ready to go.<a href="http://www.emadmokhtar.com/wp-content/uploads/2012/05/SNAG-0067.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAG-0067" border="0" alt="SNAG-0067" src="http://www.emadmokhtar.com/wp-content/uploads/2012/05/SNAG-0067_thumb.png" width="640" height="111" /></a> </li>
</ul>
</li>
<li><a href="https://github.com/toptensoftware/PetaPoco" target="_blank">Download the whole project</a> from <a href="https://github.com/" target="_blank">GitHub</a> because PetaPoco is open source project you can download it and you can even add your code if you want, after downloading the project add PetaPoco.cs file to your project. </li>
</ol>
<h2>Create POCO:</h2>
<p>Now we’ll create POCO for Customers table in <a href="http://www.microsoft.com/en-us/download/details.aspx?id=23654" target="_blank">Northwind database</a>, so let’s do it. It’s so simple just create new class and for each column in the table create a property for.</p>
<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/05/CustomerTable.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CustomerTable" border="0" alt="CustomerTable" src="http://www.emadmokhtar.com/wp-content/uploads/2012/05/CustomerTable_thumb.png" width="386" height="300" /></a></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:de177b7b-2819-4644-bb85-7f56316f7546" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Customer POCO</div>
<div style="background: #ddd; overflow: auto">
<ol start="1" style="background: #22282a; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">class</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">Customer</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">{</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> CustomerID { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> CompanyName { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> ContactName { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> ContactTitle { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Address { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> City { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Region { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> PostalCode { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Country { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e">    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Phone { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li>    <span style="color:#f1f2f3"></span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Fax { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">}</span></li>
</ol></div>
</p></div>
</p></div>
<h2>Connect To Database:</h2>
<p>In order for PetaPoco to your POCOs, you need to have database Connection String in configuration file or construct one in code, so we’ll add App.config file to the project and add a &lt;connectionString&gt; that refer to Northwind database.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:67bb842a-3bec-49ac-aa09-9aa56caccd30" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">connectionStrings</span><span style="color:#f1f2f3">&gt;</span><br />     <span style="color:#f1f2f3">&lt;</span><span style="color:#93c763">add</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">name</span><span style="color:#f1f2f3">=</span><span style="color:#ffffff">&quot;</span><span style="color:#ec7600">NorthwindConnectionString</span><span style="color:#ffffff">&quot;</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">connectionString</span><span style="color:#f1f2f3">=</span><span style="color:#ffffff">&quot;</span><span style="color:#ec7600">Data Source=.;Initial Catalog=Northwind;Integrated Security=SSPI;</span><span style="color:#ffffff">&quot;</span><br />          <span style="color:#f1f2f3"></span><span style="color:#678cb1">providerName</span><span style="color:#f1f2f3">=</span><span style="color:#ffffff">&quot;</span><span style="color:#ec7600">System.Data.SqlClient</span><span style="color:#ffffff">&quot;</span><span style="color:#f1f2f3">/&gt;</span><br /> <span style="color:#f1f2f3">&lt;/</span><span style="color:#93c763">connectionStrings</span><span style="color:#f1f2f3">&gt;</span></div>
</p></div>
</p></div>
<p>Now we are ready to make PetaPoco connect to Northwind database, and the connection can be done by Instantiate Database Object and pass the Name of the Connection String to the Contractor.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e3c554e9-4a6b-44c4-b207-824b0eb9949c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; max-height: 100px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#678cb1">Database</span><span style="color:#f1f2f3"> northwindDatabase </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">new</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">Database</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;NorthwindConnectionString&quot;</span><span style="color:#f1f2f3">);</span></div>
</p></div>
</p></div>
<h2>Perform CRUD:</h2>
<h3>Read:</h3>
<p>Read can be done by call Database Query Method and pass the POCO we want to query against.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bf5bbfa9-3a58-49de-b018-c2404696e8bc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#93c763">var</span><span style="color:#f1f2f3"> getAllCutomers </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Query</span><span style="color:#e8e2b7">&lt;</span><span style="color:#678cb1">Customer</span><span style="color:#e8e2b7">&gt;</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;SELECT * FROM Customers&quot;</span><span style="color:#f1f2f3">);</span></div>
</p></div>
</p></div>
<p>We can add parameters to the query.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:99dc94d8-e8eb-4eee-b312-8fdf15c1fa25" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">var</span><span style="color:#f1f2f3"> Cutomer </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Query</span><span style="color:#e8e2b7">&lt;</span><span style="color:#678cb1">Customer</span><span style="color:#e8e2b7">&gt;</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;SELECT * FROM Customers WHERE CustomerID=@0&quot;</span><span style="color:#f1f2f3">, </span><span style="color:#ec7600">&quot;ALFKI&quot;</span><span style="color:#f1f2f3">);</span></div>
</p></div>
</p></div>
<h3>Create:</h3>
<p>Create can be done by create new object from Customer POCO and assign its data, call Database Insert Method, and then pass Table name, Primary Key, and the POCO object.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b715b5b4-2127-4e26-a029-23c8ba8ba15e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol start="1" style="background: #22282a; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#678cb1">Customer</span><span style="color:#f1f2f3"> newCustomer </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">new</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">Customer</span><span style="color:#f1f2f3">();</span></li>
<li style="background: #161c1e">&nbsp;</li>
<li>            <span style="color:#f1f2f3"></span><span style="color:#bfbf00">//Set Data</span></li>
<li style="background: #161c1e">            <span style="color:#f1f2f3">newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">CustomerID </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#ec7600">&quot;EMAD&quot;</span><span style="color:#f1f2f3">;</span></li>
<li>            <span style="color:#f1f2f3">newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">CompanyName </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#ec7600">&quot;Microsoft&quot;</span><span style="color:#f1f2f3">;</span></li>
<li style="background: #161c1e">            <span style="color:#f1f2f3">newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">ContactName </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#ec7600">&quot;Emad Mokhtar&quot;</span><span style="color:#f1f2f3">;</span></li>
<li>            <span style="color:#f1f2f3">newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">ContactTile </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#ec7600">&quot;Developer&quot;</span><span style="color:#f1f2f3">;</span></li>
<li style="background: #161c1e">&nbsp;</li>
<li>            <span style="color:#f1f2f3"></span><span style="color:#bfbf00">//Create</span></li>
<li style="background: #161c1e">            <span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Insert(</span><span style="color:#ec7600">&quot;Customer&quot;</span><span style="color:#f1f2f3">, </span><span style="color:#ec7600">&quot;CustomerId&quot;</span><span style="color:#f1f2f3">, newCustomer);</span></li>
</ol></div>
</p></div>
</p></div>
<p>We can only pass the POCO object of we decorate our POCO Class with two PetaPoco special Attributes.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3d567b72-dfe8-4dea-89bf-6906bab18082" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; overflow: auto">
<ol start="1" style="background: #22282a; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#f1f2f3">    [</span><span style="color:#678cb1">TableName</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;Customers&quot;</span><span style="color:#f1f2f3">)]</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">    [</span><span style="color:#678cb1">PrimaryKey</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;CustomerID&quot;</span><span style="color:#f1f2f3">)]</span></li>
<li><span style="color:#f1f2f3">    </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">class</span><span style="color:#f1f2f3"> </span><span style="color:#678cb1">Customer</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">    {</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> CustomerID { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> CompanyName { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> ContactName { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> ContactTitle { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Address { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> City { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Region { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> PostalCode { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Country { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Phone { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li><span style="color:#f1f2f3">        </span><span style="color:#93c763">public</span><span style="color:#f1f2f3"> </span><span style="color:#93c763">string</span><span style="color:#f1f2f3"> Fax { </span><span style="color:#93c763">get</span><span style="color:#f1f2f3">; </span><span style="color:#93c763">set</span><span style="color:#f1f2f3">; }</span></li>
<li style="background: #161c1e"><span style="color:#f1f2f3">    }</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>&#160;</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c4b53417-cd51-4082-8017-0bf9268d1557" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Insert(newCustomer);</span></div>
</p></div>
</p></div>
</p>
<p>If you run the code an exception will be thrown because when you specify the PrimaryKey for the POCO, PetaPoco will deal with it as it’s Identity column and CustomerID isn’t identity column. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:798d7981-95b6-4fb0-b6bd-887263f49574" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL generated</div>
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;INSERT INTO [Customers] ([CompanyName],[ContactName],[ContactTitle],[Address],[City],[Region],[PostalCode],[Country],[Phone],[Fax]) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8,@9);</span><br /> <span style="color:#ec7600">SELECT SCOPE_IDENTITY() AS NewID;&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000),@1 nvarchar(4000),@2 nvarchar(4000),@3 nvarchar(4000),@4 nvarchar(4000),@5 nvarchar(4000),@6 nvarchar(4000),@7 nvarchar(4000),@8 nvarchar(4000),@9 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=N</span><span style="color:#ec7600">&#39;Microsoft&#39;</span><span style="color:#f1f2f3">,@1=N</span><span style="color:#ec7600">&#39;Emad Mokhtar&#39;</span><span style="color:#f1f2f3">,@2=N</span><span style="color:#ec7600">&#39;Developer&#39;</span><span style="color:#f1f2f3">,@3=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@4=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@5=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@6=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@7=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@8=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@9=</span><span style="color:#93c763">NULL</span></div>
</p></div>
</p></div>
<p>We will remove PrimaryKey POCO Attribute and our new customer will be inserted.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:269e296a-286f-44e3-9557-4bdbf87f78ea" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL generated</div>
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;INSERT INTO [Customers] ([CustomerID],[CompanyName],[ContactName],[ContactTitle],[Address],[City],[Region],[PostalCode],[Country],[Phone],[Fax]) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10)&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000),@1 nvarchar(4000),@2 nvarchar(4000),@3 nvarchar(4000),@4 nvarchar(4000),@5 nvarchar(4000),@6 nvarchar(4000),@7 nvarchar(4000),@8 nvarchar(4000),@9 nvarchar(4000),@10 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=N</span><span style="color:#ec7600">&#39;EMAD&#39;</span><span style="color:#f1f2f3">,@1=N</span><span style="color:#ec7600">&#39;Microsoft&#39;</span><span style="color:#f1f2f3">,@2=N</span><span style="color:#ec7600">&#39;Emad Mokhtar&#39;</span><span style="color:#f1f2f3">,@3=N</span><span style="color:#ec7600">&#39;Developer&#39;</span><span style="color:#f1f2f3">,@4=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@5=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@6=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@7=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@8=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@9=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@10=</span><span style="color:#93c763">NULL</span></div>
</p></div>
</p></div>
<h3>Update:</h3>
<p>As we did in Insert Method we can do with Update Method, but again Customers table doesn’t have identity column and this method will not work.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:944b0150-7362-4b5e-8d9a-b7d358a5c515" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#f1f2f3">newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">ContactTitle </span><span style="color:#e8e2b7">=</span><span style="color:#f1f2f3"> </span><span style="color:#ec7600">&quot;.NET Developer&quot;</span><span style="color:#f1f2f3">;</span></p>
<p> <span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Update(newCustomer);</span></div>
</p></div>
</p></div>
</p>
<p>&#160;</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e97f3f5a-d212-4496-9636-5d8846f04b49" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL generated</div>
<div style="background-color: #22282a; max-height: 400px; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;UPDATE [Customers] SET [CustomerID] = @0, [CompanyName] = @1, [ContactName] = @2, [ContactTitle] = @3, [Address] = @4, [City] = @5, [Region] = @6, [PostalCode] = @7, [Country] = @8, [Phone] = @9, [Fax] = @10 WHERE [ID] = @11&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000),@1 nvarchar(4000),@2 nvarchar(4000),@3 nvarchar(4000),@4 nvarchar(4000),@5 nvarchar(4000),@6 nvarchar(4000),@7 nvarchar(4000),@8 nvarchar(4000),@9 nvarchar(4000),@10 nvarchar(4000),@11 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=N</span><span style="color:#ec7600">&#39;EMAD&#39;</span><span style="color:#f1f2f3">,@1=N</span><span style="color:#ec7600">&#39;Microsoft&#39;</span><span style="color:#f1f2f3">,@2=N</span><span style="color:#ec7600">&#39;Emad Mokhtar&#39;</span><span style="color:#f1f2f3">,@3=N</span><span style="color:#ec7600">&#39;.NET Developer&#39;</span><span style="color:#f1f2f3">,@4=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@5=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@6=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@7=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@8=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@9=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@10=</span><span style="color:#93c763">NULL</span><span style="color:#f1f2f3">,@11=</span><span style="color:#93c763">NULL</span></div>
</p></div>
</p></div>
</p>
<p>PetaPoco have the flexibility to get the update statement that the user can write, and we’ll use this to perform the update.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5583e147-d2ff-4d56-b7b2-7edc32120074" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Update</span><span style="color:#e8e2b7">&lt;</span><span style="color:#678cb1">Customer</span><span style="color:#e8e2b7">&gt;</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;Set ContactTitle=@0 WHERE CustomerID=@1&quot;</span><span style="color:#f1f2f3">,newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">ContactTitle,newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">CustomerID);</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2faee8c2-d88f-4d80-a914-beb209de114d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL generated</div>
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;UPDATE [Customers] Set ContactTitle=@0 WHERE CustomerID=@1&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000),@1 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=N</span><span style="color:#ec7600">&#39;.NET Developer&#39;</span><span style="color:#f1f2f3">,@1=N</span><span style="color:#ec7600">&#39;EMAD&#39;</span></div>
</p></div>
</p></div>
<h3>Delete:</h3>
<p>Delete is an helper Method like Insert and Update if you are using Identity column as the Table key, you can also write your Delete statement.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:86aebbb7-4468-4fbb-8bce-4e34fc35c235" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; max-height: 100px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Delete(newCustomer);</span></div>
</p></div>
</p></div>
</p>
<p>&#160;</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9bc39ede-5cf4-4438-b399-b833bce87199" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL genetared</div>
<div style="background-color: #22282a; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;DELETE FROM [Customers] WHERE [ID]=@0&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=</span><span style="color:#93c763">NULL</span></div>
</p></div>
</p></div>
</p>
<p>We’ll write our Delete statement by pass the CustomerID we want to delete.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:52788fea-6a43-4e90-9e49-b601b713513b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; max-height: 200px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#f1f2f3">northwindDatabase</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">Delete</span><span style="color:#e8e2b7">&lt;</span><span style="color:#678cb1">Customer</span><span style="color:#e8e2b7">&gt;</span><span style="color:#f1f2f3">(</span><span style="color:#ec7600">&quot;WHERE CustomerID=@0&quot;</span><span style="color:#f1f2f3">,newCustomer</span><span style="color:#e8e2b7">.</span><span style="color:#f1f2f3">CustomerID);</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bd6bf141-e3e9-490e-8cdd-cfeab9c3b6f4" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">SQL generated</div>
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="color:#93c763">exec </span><span style="color:#f1f2f3">sp_executesql N</span><span style="color:#ec7600">&#39;DELETE FROM [Customers] WHERE CustomerID=@0&#39;</span><span style="color:#f1f2f3">,N</span><span style="color:#ec7600">&#39;@0 nvarchar(4000)&#39;</span><span style="color:#f1f2f3">,@0=N</span><span style="color:#ec7600">&#39;EMAD&#39;</span></div>
</p></div>
</p></div>
<p>You can get the whole project from <a href="https://github.com/EmadMokhtar/GettingStartPetaPoco" target="_blank">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2012/05/getting-started-petapoco-create-poco-and-perform-crud/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET Expressions</title>
		<link>http://www.emadmokhtar.com/2012/05/asp-net-expressions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-expressions</link>
		<comments>http://www.emadmokhtar.com/2012/05/asp-net-expressions/#comments</comments>
		<pubDate>Thu, 10 May 2012 07:18:00 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspnet]]></category>
		<category><![CDATA[webforms]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=898</guid>
		<description><![CDATA[ASP.NET Expression is written inline surrounded with &#60;% %&#62; in other words you will write them with your markup in .ASPX files for specific task, for example if want to access a connection string there an expression for that &#60;%$&#8230; ]]></description>
				<content:encoded><![CDATA[<p>ASP.NET Expression is written inline surrounded with &lt;% %&gt; in other words you will write them with your markup in .ASPX files for specific task, for example if want to access a connection string there an expression for that </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6d3b7f79-fd9a-48fd-bfc1-3c5be9c2555f" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #fff; overflow: auto">
<ol style="background: #000000; margin: 0; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#f1f2f3">$ ConnectionStrings:DefaultConnection </span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>Let’s lists all ASP.NET Expression and it’s task:</p>
<ol>
<li><strong>Directive Expression </strong>&lt;%@ .. %&gt;&#160;
<ul>
<li>It’s used in Web Forms .ASPX files or User Control .ASCX files to set settings, for example the Page directive where you can declare Title, Master Page, Language, etc&#8230;.
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:71543a9a-790e-415b-abbe-598f963864dd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#f1f2f3">@ </span><span style="background:#22282a;color:#a1f538">Page</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">Title=</span><span style="background:#22282a;color:#fdb62b">&quot;Home Page&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">Language=</span><span style="background:#22282a;color:#fdb62b">&quot;C#&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">MasterPageFile=</span><span style="background:#22282a;color:#fdb62b">&quot;~/Site.Master&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">AutoEventWireup=</span><span style="background:#22282a;color:#fdb62b">&quot;true&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">CodeBehind=</span><span style="background:#22282a;color:#fdb62b">&quot;Default.aspx.cs&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">Inherits=</span><span style="background:#22282a;color:#fdb62b">&quot;ASPNETExpressions._Default&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span></div>
</p></div>
</p></div>
</li>
</ul>
</li>
<li><strong>Data-Binding Expression </strong>&lt;%# .. %&gt;
<ul>
<li>Create binding between server control with data source when calling DataBind() method, most of the time you’ll see this expression inside Data Bound Controls like GridView and DetailView.
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f5f2993a-a0c2-4010-ad56-86e108a817d4" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px;"><span style="background:#22282a;color:#f1f2f3">&lt;</span><span style="background:#22282a;color:#a1f538">asp</span><span style="background:#293134;color:#e0e2e4">:</span><span style="background:#22282a;color:#a1f538">TextBox</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">runat=</span><span style="background:#22282a;color:#fdb62b">&quot;server&quot;</span><span style="background:#22282a;color:#f1f2f3"> </span><span style="background:#293134;color:#e0e2e4">ID=</span><span style="background:#22282a;color:#fdb62b">&quot;txtFirstName&quot;</span><span style="background:#22282a;color:#f1f2f3">  </span><span style="background:#293134;color:#e0e2e4">Text=</span><span style="background:#22282a;color:#fdb62b">&quot;</span><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#f1f2f3"># Eval(</span><span style="background:#22282a;color:#fdb62b">&quot;FirstName&quot;</span><span style="background:#22282a;color:#f1f2f3">) </span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span><span style="background:#22282a;color:#fdb62b">&quot;</span><span style="background:#22282a;color:#f1f2f3">/&gt;</span></div>
</p></div>
</p></div>
</li>
</ul>
</li>
<li>
<p><strong>Expression Builder</strong> &lt;%$ .. %&gt;</p>
<ul>
<li>This expression is used to set controls properties that located in configuration files <strong>Web.Config</strong> such as <strong>AppSettings, ConnectionStrings, or Resources</strong> </li>
<li>It’s syntax is <b>&lt;%$ Expression Prefix: Expression Value %&gt;</b>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:95f0c2bc-a900-415a-9b09-13a9f46e969b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#f1f2f3">$ ConnectionStrings:DefaultConnection </span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span></div>
</p></div>
</p></div>
</li>
</ul>
</li>
<li>
<p><strong>Server-side Comment Expression </strong>&lt;%&#8211; .. &#8211;%&gt;</p>
<ul>
<li>It’s to comment a block of code so that it’ll not rendered or executed inside the page.
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6d5a6d2f-8ebb-4e42-ab11-13098c0ae941" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#66747b">&#8211; This is a comment &#8211;</span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span></div>
</p></div>
</p></div>
<p>         <strong></strong></li>
</ul>
</li>
<li><strong>Displaying Expression </strong>&lt;%= .. %&gt;<strong>&#160;</strong> </li>
</ol>
<ul>
<ul>
<li>It’s the simplest way to display one piece of information such as Integer or String inside the page, it’ll be converted to <strong>Response.Write().</strong>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:de895cc5-cf68-4ffb-86bc-8414efb48a13" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #22282a; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#f1f91f;color:#8c8cb4">&lt;%</span><span style="background:#22282a;color:#f1f2f3">= </span><span style="background:#22282a;color:#678cb1">DateTime</span><span style="background:#22282a;color:#e8e2b7">.</span><span style="background:#22282a;color:#f1f2f3">UtcNow</span><span style="background:#22282a;color:#e8e2b7">.</span><span style="background:#22282a;color:#f1f2f3">ToString(</span><span style="background:#22282a;color:#fdb62b">&quot;dd/MM/yyyy&quot;</span><span style="background:#22282a;color:#f1f2f3">) </span><span style="background:#f1f91f;color:#8c8cb4">%&gt;</span></div>
</p></div>
</p></div>
</li>
</ul>
<ul></ul>
<ul></ul>
</ul>
<h3><font size="2"><u>Tip:</u></font></h3>
<p>Every time you’ll see &lt;% look at the next character:</p>
<ul>
<li>If it @ then it’s<strong> Directive Expression</strong>. </li>
<li>If it = then it’s <strong>Displaying Expression</strong>. </li>
<li>If it # then it’s <strong>Data-Binding Expression</strong>. </li>
<li>If it &#8212; then it’s <strong>Comment</strong>. </li>
<li>If it $ then it’s<strong> Expression Builder</strong>. </li>
</ul>
<p><strong><u>Note:</u></strong></p>
<p>If you make incorrect syntax inside these expression, Exception will be thrown.</p>
<p><span id="more-898"></span>
<p><font style="font-weight: normal" size="2">Microsoft Support: <a href="http://support.microsoft.com/kb/976112" target="_blank">Introduction to ASP.NET inline expressions in the .NET Framework</a></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2012/05/asp-net-expressions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET Page Lifecycle in Plain English</title>
		<link>http://www.emadmokhtar.com/2012/05/asp-net-page-lifecycle-in-plain-english/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-page-lifecycle-in-plain-english</link>
		<comments>http://www.emadmokhtar.com/2012/05/asp-net-page-lifecycle-in-plain-english/#comments</comments>
		<pubDate>Thu, 03 May 2012 07:38:00 +0000</pubDate>
		<dc:creator>Emad Mokhtar</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspnet]]></category>

		<guid isPermaLink="false">http://www.emadmokhtar.com/?p=896</guid>
		<description><![CDATA[ASP.NET Page Lifecycle is very important piece of knowledge every ASP.NET developer must know, and unfortunately some of ASP.NET developer out there don’t know and they think it’s not important to know. Let’s dig in and let’s examine ASP.NET Lifecycle&#8230; ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.emadmokhtar.com/wp-content/uploads/2012/05/asp.net_.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="asp.net" border="0" alt="asp.net" align="right" src="http://www.emadmokhtar.com/wp-content/uploads/2012/05/asp.net_thumb.jpg" width="376" height="96" /></a></p>
<p>ASP.NET Page Lifecycle is very important piece of knowledge every ASP.NET developer must know, and unfortunately some of ASP.NET developer out there don’t know and they think it’s not important to know.</p>
<p>Let’s dig in and let’s examine ASP.NET Lifecycle but in short list and description:</p>
<ol>
<li><strong>PreInit():</strong>
<ul>
<li>In this event all Controls created and Initialized with their default values. You can create dynamic Controls here. You can set theme programmatically here </li>
</ul>
</li>
<li><strong>OnInit():</strong>
<ul>
<li>In this event you can read the Controls properties the were set in Design Mode and can not read values changed by user. </li>
</ul>
</li>
<li><strong>LoadViewState():</strong>
<ul>
<li>This event fires only if the page is posted back “<strong>IsPostback == true;</strong>” and here View State data where are stored in hidden form fields get de-serialized and loads all controls View State data. </li>
</ul>
</li>
<li><strong>LoadPostBackData():</strong>
<ul>
<li>This event only fires when Page is posted back and Controls which implement <strong>IPostBackDataHandler</strong> interface get loaded with values from <strong>HTTP POST</strong> data. </li>
</ul>
</li>
<li><strong>Page_Load():</strong>
<ul>
<li>This event is well known among ASP.NET developers and here Page gets loaded and after it all <strong>Load()</strong> events of Page Controls fired. </li>
</ul>
</li>
<li><strong>Control Event Handlers:</strong>
<ul>
<li>These are basically event handlers like Button click event handler “Button1_Click()” which fires after <strong>Page_Load() </strong>event. </li>
</ul>
</li>
<li><strong>PreRender():</strong>
<ul>
<li>This event is fired for each page child controls and her you can change controls values. </li>
</ul>
</li>
<li><strong>SaveViewState():</strong>
<ul>
<li>In this event Controls View State saved in Page hidden fields. </li>
</ul>
</li>
<li><strong>Render():</strong>
<ul>
<li>Here all Controls get rendered or every Page Controls Render method is called. </li>
</ul>
</li>
<li><strong>Unload():</strong>
<ul>
<li>Here we can have Page and Controls clean up operations. This event the Page and its Controls are rendered. </li>
</ul>
</li>
</ol>
<p><strong>Notes:</strong></p>
<ol>
<li>ASP.NET Lifecycle will be called ever time there a request for the page. </li>
<li>HTTP POST data has only one value per control, that’s why Control like Textbox can gets value from HTTP Post but Control like DropDownList can not gets data from HTTP Post it can gets data from View State. </li>
<li><strong>Init()</strong> and <strong>Unload()</strong> events are fired from outside to inside controls, fro example: user control Init() event will be fired before <strong>Page_Init()</strong> event </li>
</ol>
<p>Reference: <a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx" target="_blank">ASP.NET Page Lifecycle on MSDN</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadmokhtar.com/2012/05/asp-net-page-lifecycle-in-plain-english/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
