این لایه DAL هست ... واسه یه جدول به اسم Agent :
using System;using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class Agent
{
public string ConString = "Data Source=.;Initial Catalog=Rahgoshafan;Integrated Security=True";
SqlConnection con = new SqlConnection();
DataTable dt = new DataTable();
public string Agent;
public string Mobile;
public byte Pic;
public string Toz;
public DataTable Read()
{
con.ConnectionString = ConString;
if (ConnectionState.Closed == con.State)
con.Open();
SqlCommand cmd = new SqlCommand("Select * From Agent", con);
try
{
SqlDataReader rd = cmd.ExecuteReader();
dt.Load(rd);
return dt;
}
catch
{
throw;
}
}
public void Insert()
{
con.ConnectionString = ConString;
if (ConnectionState.Closed == con.State)
con.Open();
SqlCommand cmd = new SqlCommand("Insert Into Agent (Agent, Mobile, Pic, Toz) Values (N'{0}', N'{1}', '{3}' ,N'{4}')", con);
try
{
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
}
public void Delete()
{
con.ConnectionString = ConString;
if (ConnectionState.Closed == con.State)
con.Open();
SqlCommand cmd = new SqlCommand("Delete From TGroup Where Id = {0}", con);
try
{
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
}
public void Update()
{
con.ConnectionString = ConString;
if (ConnectionState.Closed == con.State)
con.Open();
SqlCommand cmd = new SqlCommand("Update TGroup Set Agent = N'{0}', Mobile = N'{1}', Pic = '{2}', Toz = N'{3}' Where Id = {4}", con);
try
{
cmd.ExecuteNonQuery();
}
catch
{
throw;
}
}
}
}
این لایه BLL هستش :
using System;using System.Collections.Generic;
using System.Data;
using DAL;
namespace BLL
{
public class Agent_BLL
{
public DataTable Get_Agent()
{
try
{
Agent Agent_Read = new Agent();
return Agent_Read.Read();
}
catch
{
throw;
}
}
public void Insert_Agent()
{
try
{
Agent Agent_Insert = new Agent();
Agent_Insert.Insert();
}
catch
{
throw;
}
}
public void Delete_Agent()
{
try
{
Agent Agent_Delete = new Agent();
Agent_Delete.Delete();
}
catch
{
throw;
}
}
public void Update_Agent()
{
try
{
Agent Agent_Update = new Agent();
Agent_Update.Update();
}
catch
{
throw;
}
}
}
}
حالا همه فرم هام اینجوری شدن ! (عکس ضمیمه)