Professional Documents
Culture Documents
NET
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace noor
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=LAB06-9\SQL2K14;Initial Catalog=noor;Integrated
Security=True");
public Form1()
{
InitializeComponent();
}
Insertion:
private void button1_Click(object sender, EventArgs e)
{
string g = null;
if (rd1.Checked)
g = "Male";
else
g = "Female";
String q = "insert into employee(Name,Gender,Address) values('" + txt1 + "','" + g + "','" + txt2 + "') ";
SqlCommand cmd = new SqlCommand(q, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
MessageBox.Show("Inserted");
else
MessageBox.Show(" Not Inserted");
}
Updation:
private void button4_Click(object sender, EventArgs e)
{
string g = null;
if (rd1.Checked)
g = "Male";
else
g = "Female";
String q = "update employee set( Name='" + txt1 + "',Gender='" + g + "',Address'" + txt2 + "') where id =1 ";
SqlCommand cmd = new SqlCommand(q, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
MessageBox.Show("Updated");
else
MessageBox.Show(" Not Updated");
}
}
}
Deletion:
private void button2_Click(object sender, EventArgs e)
{
con.Open();
string query = "delete from Student where SId=1";
SqlCommand cmd = new SqlCommand(query, con);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
MessageBox.Show("Data Deleted");
else
MessageBox.Show("Data not Deleted ");
}
Selection:
private void Form1_Load(object sender, EventArgs e)
{
string q = "select Id,Name,Address from Student";
SqlCommand cmd = new SqlCommand(q, con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
//dataGridView1.DataSource = dt;
listBox1.Items.Add(selectedItem);
}
Three Tier:
Data Layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BO;
using System.Data.SqlClient;
namespace DAL
{
public class DALClass
{
public int InsertData(BOclass b)
{
try {
SqlConnection con = new SqlConnection(@"Data Source=HAIRE;Initial Catalog=SPMor6A;Integrated
Security=True");
SqlCommand cmd = new SqlCommand("InsertData", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name",b.Name);
cmd.Parameters.AddWithValue("@gender",b.Gender);
cmd.Parameters.AddWithValue("@edu",b.Education);
cmd.Parameters.AddWithValue("@dates",b.Datetime);
con.Open();
int i=cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
return 1;
else
return 0;
}
catch
{
throw;
}
}
}
}
BO layer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BO
{
public class BOclass
{
int id;
string name;
string gender;
string education;
DateTime datetime;
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
set
{
name = value;
}
}
set
{
gender = value;
}
}
set
{
education = value;
}
}
set
{
datetime = value;
}
}
}
}
Buisness Logic Layer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using BO;
namespace BLL
{
public class BLLClass
{
public int Insert(BOclass b)
{
DALClass d = new DALClass();
int i=d.InsertData(b);
if (i > 0)
return 1;
else
return 0;
}
}
}
Asp.net
protected void form_Load(object sender, EventArgs e)
int result = 0;
if (number % 2 == 0)
result = CalculateFactorial(number);
else
TextBox1.Text = result.ToString();
int result = 1;
result *= number;
number--;
return result;