
- Application layer is the form where we design using the controls like textbox, labels, command buttons etc.
- Business layer is the class where we write the functions which get the data from the application layer and passes through the data access layer.
- Data layer is also the class which gets the data from the business layer and sends it to the database or gets the data from the database and sends it to the business layer.
- Property layer is the sub layer of the business layer in which we make the properties to sent or get the values from the application layer. These properties help to sustain the value in a object so that we can get these values till the object destroy
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public class person
{
SqlConnection myconn = new SqlConnection("server=isa;database=CuteChat4;uid=sa;password=sa");
public person()
{
//
// TODO: Add constructor logic here
//
}
///
/// Used to insert records into database
///
{
myconn.Open();
SqlCommand cmd = new SqlCommand("insertnews", myconn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@description", description);
return cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
myconn.Close();
myconn.Dispose();
}
}
///
/// Update record into database
///
{
myconn.Open();
SqlCommand cmd = new SqlCommand("updatenews", myconn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@description", description);
return cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
myconn.Close();
myconn.Dispose();
}
}
///
/// Shows all records from database
///
public DataTable show()
{
SqlDataAdapter da = new SqlDataAdapter("selectnews", myconn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
try
{
da.Fill(ds, "news");
return ds.Tables["news"];
}
catch
{
throw;
}
finally
{
ds.Dispose();
da.Dispose();
myconn.Close();
myconn.Dispose();
}
}
public DataTable show1(int id)
{
SqlDataAdapter da = new SqlDataAdapter("select* from news where id=" + id, myconn);
da.SelectCommand.CommandType = CommandType.Text;
DataSet ds = new DataSet();
try
{
da.Fill(ds, "news");
return ds.Tables["news"];
}
catch
{
throw;
}
finally
{
ds.Dispose();
da.Dispose();
myconn.Close();
myconn.Dispose();
}
}
///
/// Delete record from database
///
public int delete(int id)
{
myconn.Open();
SqlCommand cmd = new SqlCommand("deletenews", myconn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@id", id);
return cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
myconn.Close();
myconn.Dispose();
}
}
}

2 comments:
yeh kiski codin hai bhai mere ko to smaj hi nai aae... hehe
mere to sir ke upar se nikal gye...
Post a Comment