Hi Guys !
Can anybody give me the sample coding, how to use BAL & DAL (should have transaction scope) for my web based database application ? I'm using C# and .net framework 3.5.
Thanks & Regards
Suhesh.S
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
selvi subramanianPosted Feb 3, 2014, 12:27 AM
kiran nathPosted Jan 30, 2014, 4:12 AM
selvi subramanianPosted Jan 11, 2013, 1:35 AM
suhesh selladuraiPosted Jan 9, 2013, 6:54 AM
suhesh selladuraiPosted Jan 9, 2013, 6:54 AM
selvi subramanianPosted Jan 9, 2013, 4:13 AM
1st u have to create a folder in the name of DAL
2nd to create in the name of BAL
3rd u have to design a page
DAL code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
///
/// Summary description for DAL
///
public class DAL
{
string s = ConfigurationManager.AppSettings["ss"].ToString();
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
public DAL()
{
//
// TODO: Add constructor logic here
//
}
public int inset(string FName, string Age, string Resume)
{
con = new SqlConnection(s);
con.Open();
try
{
string qr="insert into thretier(FName,Age,Resume) values ('" + FName + "','" + Age + "','" + Resume + "')";
cmd = new SqlCommand(qr,con);
return cmd.ExecuteNonQuery();
}
catch {
throw;
}
finally
{
cmd.Dispose();
con.Dispose();
con.Close();
}
}
public DataTable selcc()
{
con = new SqlConnection(s);
con.Open();
try
{
string qry="select * from thretier";
cmd=new SqlCommand(qry,con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
da.Fill(dt);
return dt;
}
catch(Exception)
{
throw;
}
finally
{
cmd.Dispose();
con.Dispose();
con.Close();
}
}
}
BAL code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///
/// Summary description for BAL
///
public class BAL
{
DAL ash=new DAL();
public BAL()
{
//
// TODO: Add constructor logic here
//
}
public int inset(string FName, string Age, string Resume)
{
try
{
return ash.inset(FName, Age, Resume);
}
catch
{
throw;
}
finally
{
ash = null;
}
}
public DataTable getdaa()
{
try
{
return ash.selcc();
}
catch
{
throw;
}
finally
{
}
}
}
3rd design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
BAL selv = new BAL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
aggg();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
aggg();
string Filena = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName.ToString());
string save = Server.MapPath("Resume") + "\\" + Filena;
if (FileUpload1.PostedFile != null)
{
FileUpload1.PostedFile.SaveAs(save);
}
string FName = txname.Text;
string Age = tage.Text;
string Resume = Filena.ToString();
int dash;
dash=selv.inset(FName,Age,Resume);
}
private void aggg()
{
ListItem li = new ListItem();
li.Text = "Select";
li.Value = "0";
ddag.Items.Add(li.ToString());
for (int i = 0; i <= 100; i++)
{
ddag.Items.Add(Convert.ToString(i));
}
}
}
Vishnujeet KumarPosted Jan 7, 2013, 10:33 AM
http://www.c-sharpcorner.com/uploadfile/hgvyas123/3-tier-architecture/
http://www.dotnetfunda.com/articles/article71.aspx