<?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>NSRajesh</title>
	<atom:link href="http://www.nsrajesh.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nsrajesh.com</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 12:03:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.Net/C# – Creating Business Logic Layer / Data Access Layer &#8211; Part 2</title>
		<link>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer-part-2/</link>
		<comments>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer-part-2/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 05:28:45 +0000</pubDate>
		<dc:creator>nsrajesh</dc:creator>
				<category><![CDATA[ASP.Net]]></category>

		<guid isPermaLink="false">http://www.nsrajesh.com/?p=104</guid>
		<description><![CDATA[Download this Tutorial Project
Please make comment is you think this articles helps you.
In Part 1 we saw how to create all 3 layers (UI, BLL, DAL). So in this project we are going to see how all three projects are going to interact with each other.
1. UI Layer – User will enter the User Name [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/downloads/BLL-DAL-GUI-sampleproject.rar"><strong>Download this Tutorial Project</strong></a></p>
<p><em>Please make comment is you think this articles helps you.</em></p>
<p>In <a href="http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer/">Part 1</a> we saw how to create all 3 layers (UI, BLL, DAL). So in this project we are going to see how all three projects are going to interact with each other.</p>
<p>1. UI Layer – User will enter the User Name / Password to enter into  our project.</p>
<p>2. BLL – We will check whether he entered both the User Name &amp;  password – if not we will show them an error like “Please enter the User  Name” or  “Please enter the Password”.</p>
<p>3. DAL – If the user entered both the “User name &amp; Password” then  will check that User Name &amp; Password in the database – whether its  correct or not.</p>
<p>This is how all three projects will interact with each other.</p>
<p><em>Note: we are not going to concentrate on Login Page or any other pages design part.</em></p>
<p><strong>Step 1:</strong><br />
Open the &#8220;Default.aspx&#8221; page. Place three Label Controls &amp; two TextBox Controls. Name the textbox controls like<strong> &#8220;txtUserName&#8221;</strong> &amp;<strong> &#8220;txtPassword&#8221;</strong>.</p>
<p>Place a new command button after those text box &amp; name it as <strong>&#8220;cmdLogin&#8221;</strong>.</p>
<p>Now &#8220;Default.aspx&#8221; page will look like this:</p>
<p><em>&lt;asp:Label runat=&#8221;server&#8221; ID=&#8221;lblError&#8221; Text=&#8221;"&gt;&lt;/asp:Label&gt;&lt;br /&gt;</em><em>&lt;br /&gt;</em><em>&lt;br /&gt;</em></p>
<p><em>&lt;asp:Label runat=&#8221;server&#8221; ID=&#8221;Label1&#8243; Text=&#8221;User Name&#8221;&gt;&lt;/asp:Label&gt;<br />
&lt;asp:TextBox runat=&#8221;server&#8221; ID=&#8221;txtUserName&#8221;&gt;&lt;/asp:TextBox&gt; &lt;br /&gt;&lt;br /&gt;</em></p>
<p><em>&lt;asp:Label runat=&#8221;server&#8221; ID=&#8221;Label2&#8243; Text=&#8221;User Name&#8221;&gt;&lt;/asp:Label&gt;<br />
&lt;asp:TextBox runat=&#8221;server&#8221; ID=&#8221;txtPassword&#8221;&gt;&lt;/asp:TextBox&gt; &lt;br /&gt;&lt;br /&gt;</em></p>
<p><em>&lt;asp:Button runat=&#8221;server&#8221; ID=&#8221;cmdLogin&#8221; Text=&#8221;Login&#8221; /&gt;</em></p>
<p><em>==================================================================</em></p>
<p>When you run this project (F5) the page will look like this in Browser:</p>
<p><img class="alignnone size-full wp-image-110" title="Login Page" src="http://www.nsrajesh.com/uploads/login-page.GIF" alt="Login Page" width="357" height="212" /></p>
<p><strong>Step 2:</strong><br />
Now we should work on Database Access. First create one database called &#8220;<strong>SampleProject</strong>&#8221; in your MS SQL. Then create only one table named &#8220;<strong>MUser</strong>&#8221; with following fields.</p>
<p>1. UserID &#8211; Int<br />
2. UserName &#8211; varchar(128)<br />
3. UserPassword &#8211; varchar(256)</p>
<p>Then enter one record into the database table for testing purpose&#8230; like<br />
UserName: admin<br />
UserPassword: adminpass</p>
<p>Now we should write a stored procedure to get these Records from Database table. So the stored procedure will look like this.</p>
<p>CREATE PROC [dbo].[sp_User_Login]<br />
@UserName varchar(128), @UserPassword varchar(256)<br />
AS<br />
BEGIN<br />
SELECT<br />
*<br />
FROM<br />
MUser<br />
WHERE<br />
UserName = @UserName<br />
AND<br />
UserPassword = @UserPassword<br />
END</p>
<p><strong>Step 3:</strong><br />
Now we need to code the Data Access Layer. We need to add these reference to our Data Access Layer.</p>
<p>Microsoft.Practices.EnterpriseLibrary.Common.dll<br />
Microsoft.Practices.EnterpriseLibrary.Data.dll</p>
<p>Then <strong>add new Class file (.cs) called DAUser.cs</strong> to the DAL project. We are going to user this file to access our database.<br />
Once we added these references (dll) &amp; Class file (.cs) we need to write code to access the database. The DAL Code in DAUser.cs page will look like this below.</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Data;<br />
using System.Data.Common;<br />
using Microsoft.Practices.EnterpriseLibrary.Data;<br />
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;</p>
<p>namespace SampleProject.DataAccess<br />
{<br />
public class DAUser<br />
{<br />
public DataSet UserLogin(string UserName, string UserPassword)<br />
{</p>
<p>//DBNameIs &#8211; is coming from web.config file &#8211; connectionStrings section<br />
DataSet ds = new DataSet();<br />
Database db = DatabaseFactory.CreateDatabase(&#8221;DBNameIs&#8221;);<br />
DbCommand cmd = db.GetStoredProcCommand(&#8221;sp_User_Login&#8221;);<br />
db.AddInParameter(cmd, &#8220;UserName&#8221;, DbType.String, UserName.Trim());<br />
db.AddInParameter(cmd, &#8220;UserPassword&#8221;, DbType.String, UserPassword.Trim());<br />
ds = db.ExecuteDataSet(cmd);<br />
return ds;<br />
}<br />
}<br />
}</p>
<p>Thats it!. Now Database is ready, as well as DAL is also ready.</p>
<p><strong>Step 4:</strong><br />
Now we should write code to check whether the entered Username &amp; Password is correct or not. We are going to write this code in Business Logic Layer (BLL).</p>
<p>Before this we need to <strong>Add DAL reference to BLL Layer</strong>, so that BLL layer can access the data from DAL layer (Hope you understand this step). So how to add this Reference??</p>
<p>In Solution Explorer in BLL layer Right click on the &#8220;Reference&#8221; &amp; again click on &#8220;Add Reference&#8221; menu . It will show you a dialog box as shown below.</p>
<p><img class="alignnone size-full wp-image-113" title="BLL - DAL Reference" src="http://www.nsrajesh.com/uploads/bll-dal-reference.gif" alt="BLL - DAL Reference" width="480" height="396" /></p>
<p>Now click on Project tab &amp; select the &#8220;SampleProject.DataAccess&#8221; project &amp; click ok. Now we added DAL reference to BLL.</p>
<p>Our next step is to create the Logic. So now add a New class file to BLL project &#8211; named &#8220;<strong>BLUser.cs</strong>&#8221;</p>
<p>Now write the login logic as below</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using SampleProject.DataAccess;<br />
using System.Data;</p>
<p>namespace SampleProject.BusinessLogic<br />
{<br />
public class BLUser<br />
{<br />
public bool UserLogin(string UserName, string UserPassword)<br />
{<br />
//Data Access Layer Object.<br />
DAUser objUser = new DAUser();</p>
<p>//Now we are getting details from Database.<br />
DataSet ds = new DataSet();<br />
ds = objUser.UserLogin(UserName, UserPassword);</p>
<p>//If the username &amp; password matchs then Stored Procedure will return User Details<br />
//So if we have any rows it means User entered Correct Username / Password.<br />
if (ds.Tables.Count &gt; 0 &amp;&amp; ds.Tables[0].Rows.Count &gt; 0)<br />
{<br />
return true;<br />
}<br />
else<br />
{<br />
return false;<br />
}<br />
}<br />
}<br />
}</p>
<p>That&#8217;s it. Now BLL is also ready.</p>
<p><strong>Step 4:</strong><br />
Now we should get the username / password &amp; pass those to BLL.</p>
<p>Add the reference to the BLL project from UI project. Once you added the reference open the &#8220;default.aspx&#8221; page add this line:<br />
using SampleProject.BusinessLogic;</p>
<p>Then we need to write the code in Button click to check the given username / password. So it will be like this:</p>
<p>using System;<br />
using System.Configuration;<br />
using System.Data;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Xml.Linq;<br />
using SampleProject.BusinessLogic;</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{</p>
<p>}</p>
<p>protected void cmdLogin_Click(object sender, EventArgs e)<br />
{<br />
BLUser objUser = new BLUser();<br />
if (objUser.UserLogin(this.txtUserName.Text, this.txtPassword.Text))<br />
{<br />
this.lblError.Text = &#8220;Logged In Successfully.&#8221;;<br />
}<br />
else<br />
{<br />
this.lblError.Text = &#8220;Invalid Username / password.&#8221;;<br />
}<br />
}<br />
}</p>
<p>Now run the project &amp; test with sample username / password. <a href="/downloads/BLL-DAL-GUI-sampleproject.rar"><strong>Download this tutorial project.</strong></a></p>
<p><em>If you still have issues please let me know through comment. I will try to help you &#8211; even on skype chat.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net/C# &#8211; Creating Business Logic Layer / Data Access Layer</title>
		<link>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer/</link>
		<comments>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 06:49:49 +0000</pubDate>
		<dc:creator>nsrajesh</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.nsrajesh.com/?p=80</guid>
		<description><![CDATA[Download this Tutorial Project
Please make comment is you think this articles helps you.
How to create/use Business Logic Layer / Data Access Layer in ASP.Net project
Do you guys know how to create a Simple ASP.Net project with Business Logic Layer (BLL) &#38; Data Access Layer (DAL) along with Presentation Layer or User Interface Layer (UI) &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/downloads/BLL-DAL-GUI-sampleproject.rar"><strong>Download this Tutorial Project</strong></a></p>
<p><em>Please make comment is you think this articles helps you.</em></p>
<h2>How to create/use Business Logic Layer / Data Access Layer in ASP.Net project</h2>
<p>Do you guys know how to create a Simple ASP.Net project with Business Logic Layer (BLL) &amp; Data Access Layer (DAL) along with Presentation Layer or User Interface Layer (UI) &#8211; Simply ASP.Net Project&#8230;</p>
<p>Lets learn together.</p>
<p><strong>First step</strong> is to Create an ASP.Net project (hope you guys know how to create ASP.Net Project <img src='http://www.nsrajesh.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) &#8211; Lets name it as &#8220;SampleProject&#8221;.  While saving the project Save it in your <strong>wwwroot Folder</strong>. Mostly it will be in C:\Inetpub\wwwroot\.</p>
<p>Now you solution explorer will look like this.<br />
<img src="file:///C:/DOCUME%7E1/RAJESH%7E1.TEN/LOCALS%7E1/Temp/moz-screenshot.png" alt="" /></p>
<div id="attachment_81" class="wp-caption alignnone" style="width: 367px"><img class="size-full wp-image-81" title="solution-exporer-dal-bal-asp" src="http://www.nsrajesh.com/uploads/solution-exporer-dal-bal-asp.gif" alt="DAL-BAL-Solution-Explorer" width="357" height="212" /><p class="wp-caption-text">DAL-BAL-Solution-Explorer</p></div>
<h3><strong>Creating BLL</strong></h3>
<p>Our next step is to create the Business Logic Layer (BLL) &amp; Data Access Layer (DAL) &#8211; From now on we will call it as BLL / DAL. For BLL &amp; DAL layer we need to create DLL Files &#8211; using Class Library Projects. So just right click on your Project&#8217;s Solution file as show below.</p>
<div id="attachment_86" class="wp-caption alignnone" style="width: 367px"><img class="size-full wp-image-86" title="select-solution-dal-bal-asp.net" src="http://www.nsrajesh.com/uploads/select-solution-dal-bal-asp.net.gif" alt="Selecting Solution to add BLL &amp; DAL" width="357" height="212" /><p class="wp-caption-text">Selecting Solution to add BLL &amp; DAL</p></div>
<p>Now select <strong>Windows</strong> in Project Type &#8211; left hand side of the dialog box. Then select <strong>Class Library</strong> in Templates &#8211; right hand side. Now give the project name as &#8220;<strong>SampleProject.BusinessLogic</strong>&#8221; &#8211; Save this project in <strong>wwwroot</strong> folder itself.</p>
<p>Now your project explorer will look like below.</p>
<p><img class="alignnone size-full wp-image-96" title="solution-exporer-bal-asp" src="http://www.nsrajesh.com/uploads/solution-exporer-bal-asp.gif" alt="solution-exporer-bal-asp" width="357" height="205" /></p>
<h3><strong><strong>Creating DAL</strong></strong></h3>
<p>Follow the same steps that you used to create the BLL  to create the DAL project and name the project as &#8220;<strong>SampleProject.DataAccess</strong>&#8220;.</p>
<p>This is how your solution explorer will look like now.</p>
<p><img class="alignnone size-full wp-image-101" title="Solution Exporer with UI Layer, BLL, DAL" src="http://www.nsrajesh.com/uploads/solution-exporer-gui-bal-dal-asp.gif" alt="Solution Exporer with UI Layer, BLL, DAL" width="357" height="212" /></p>
<h3><strong>Using all three Layers</strong></h3>
<p>Now we have UI, BLL &amp; DAL projects is in place. So how we are going to interact all these projects. Now we are going to create a login page where users can login.</p>
<p><strong><span style="color: #ff6600;">And <em>we are not going to use any ASP.Net controls like Login / Login View / Login Status</em> etc&#8230; to create this login page. Also we are going to use <a href="http://msdn.microsoft.com/en-us/library/cc467894.aspx">Microsoft Enterprise Library</a> to access the Database. If you don&#8217;t know Enterprise Library, please don&#8217;t worry &#8211; Its just like OLEDB.<br />
</span></strong></p>
<p>Now, while the user logs in into our product our all projects (UI, BLL &amp; DAL) will interact like below.</p>
<p>1. UI Layer &#8211; User will enter the User Name / Password to enter into our project.</p>
<p>2. BLL &#8211; We will check whether he entered both the User Name &amp; password &#8211; if not we will show them an error like &#8220;Please enter the User Name&#8221; or &#8220;Please enter the Password&#8221;.</p>
<p>3. DAL &#8211; If the user entered both the &#8220;User name &amp; Password&#8221; then will check that User Name &amp; Password in the database &#8211; whether its correct or not.</p>
<p>This is how all three projects will interact with each other.</p>
<p><em><strong>Please read the Part 2 of this tutorial</strong></em></p>
<p><em>If you still have issues please let me know through comment. I will try to help you &#8211; even on skype chat.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nsrajesh.com/asp-dot-net-creating-business-logic-layer-data-access-layer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First Blog Post</title>
		<link>http://www.nsrajesh.com/my-first-blog-post/</link>
		<comments>http://www.nsrajesh.com/my-first-blog-post/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 07:54:47 +0000</pubDate>
		<dc:creator>nsrajesh</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Adwords API]]></category>

		<guid isPermaLink="false">http://www.nsrajesh.com/?p=65</guid>
		<description><![CDATA[Hi all, This is my first post on my Blog. From today onwards i will try my level best to give you use full articles/projects. Also if you need any help with your ASP.Net / C#/ PHP projects please let me know. I will try my level best to help you.
Thanks.
]]></description>
			<content:encoded><![CDATA[<p>Hi all, This is my first post on my Blog. From today onwards i will try my level best to give you use full articles/projects. Also if you need any help with your ASP.Net / C#/ PHP projects please let me know. I will try my level best to help you.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nsrajesh.com/my-first-blog-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
