0% found this document useful (0 votes)
12 views3 pages

Ahmed

The document contains code for a C# Windows Forms application that manages employee data in a SQL database. It connects to the database, displays employee data in a datagrid, and allows adding and updating employee records.

Uploaded by

abdirisaqboon7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Ahmed

The document contains code for a C# Windows Forms application that manages employee data in a SQL database. It connects to the database, displays employee data in a datagrid, and allows adding and updating employee records.

Uploaded by

abdirisaqboon7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;

namespace Electronic_shop_management_system
{
public partial class Employee : Form
{
public Employee()
{
InitializeComponent();
DisplayEmloyee();
}
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\
MSSQLLocalDB;AttachDbFilename=C:\Users\carafat dheeg\Documents\
Alnasrishop.mdf;Integrated Security=True;Connect Timeout=30");
private void DisplayEmloyee()
{
con.Open();
string Quary = "select * from employee";
SqlDataAdapter sql = new SqlDataAdapter(Quary, con);
SqlCommandBuilder builder = new SqlCommandBuilder(sql);
var dataSet = new DataSet();
sql.Fill(dataSet);
EmployeeDGH.DataSource = dataSet.Tables[0];
con.Close();
}
private void Clear()
{
EmpNameTb.Text = "";
EmpAddressTb.Text = "";
EmpFormTb.Text = "";
EmpSalaryTb.Text = "";
}

private void savebtn_Click(object sender, EventArgs e)


{
if (EmpNameTb.Text == "" || EmpAddressTb.Text == "" || EmpFormTb.Text
== "" || EmpSalaryTb.Text =="")
{
MessageBox.Show("Missing information");
}
else
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into Employee
(Empname,Address,Form,Salary)values(@En,@EA,@f,@S)", con);
cmd.Parameters.AddWithValue("@En", EmpNameTb.Text);
cmd.Parameters.AddWithValue("@EA", EmpAddressTb.Text);
cmd.Parameters.AddWithValue("@f", EmpFormTb.Text);
cmd.Parameters.AddWithValue("@S", EmpSalaryTb.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Employee Added");
con.Close();
DisplayEmloyee();
Clear();

}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

private void panel3_Paint(object sender, PaintEventArgs e)


{

private void EmployeeDGH_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
EmpNameTb.Text = EmployeeDGH.SelectedRows[0].Cells[1].Value.ToString();
EmpAddressTb.Text =
EmployeeDGH.SelectedRows[0].Cells[2].Value.ToString();
EmpFormTb.Text = EmployeeDGH.SelectedRows[0].Cells[3].Value.ToString();
EmpSalaryTb.Text =
EmployeeDGH.SelectedRows[0].Cells[4].Value.ToString();
if (EmpNameTb.Text == "") ;
}

private void EmpNameTb_TextChanged(object sender, EventArgs e)


{

private void updatebtn_Click(object sender, EventArgs e)


{
if (EmpNameTb.Text == "" || EmpAddressTb.Text == "" || EmpFormTb.Text
== "" || EmpSalaryTb.Text == "")
{
MessageBox.Show("Missing information");
}
else
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("Update Employee set
Empname=@En,Address=@EA,Form=,@f,Salary=@S, where Empname=Ekey)", con);
cmd.Parameters.AddWithValue("@En", EmpNameTb.Text);
cmd.Parameters.AddWithValue("@EA", EmpAddressTb.Text);
cmd.Parameters.AddWithValue("@f", EmpFormTb.Text);
cmd.Parameters.AddWithValue("@S", EmpSalaryTb.Text);

cmd.ExecuteNonQuery();
MessageBox.Show("Employee Updated!!!");
con.Close();
DisplayEmloyee();
Clear();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

You might also like