Abstract Class in 3tier-Arch.

Dotnet4ashu
Posted by Dotnet4ashu under ASP.NET category on | Points: 40 | Views : 2347
For Using Abstract Class
First Need is to create BAL Common Class with (members,methods and properties) and DAL Connection Class In AppCode

BALCommon Class
//Main Class
public abstract class BalCommon
{
#region Members
private int _id;
private string _name;
#endregion


#region Properties
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
#endregion

#region Methods
public abstract int BalIns();

#endregion
}
DAL Common Class

public class DalConnection:BalCommon //Inheriting Class
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
SqlCommand cmd;


public override int BalIns()
{
cmd = new SqlCommand("rr", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Id);
cmd.Parameters.AddWithValue("@name", Name);
cmd.ExecuteNonQuery();
con.Close();
return (0);
}

}

AT Default ASPX
//Classing DAL Connection Class with BAL Common Class Method balinsert()
On Button Cl ick
protected void Button1_Click(object sender, EventArgs e)
{
DalConnection obj = new DalConnection();
obj.Id = Convert.ToInt32(TextBox1.Text);
obj.Name = TextBox2.Text;
int y = obj.BalIns();
if (y == 0)
{
Response.Write("d saved");
}
else
{
Response.Write("not saved");
}
}

Comments or Responses

Posted by: T.Saravanan on: 2/20/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

Kindly post your code inside the code tag.

Login to post response