Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace EmployeesData
- {
- public partial class Form2 : Form
- {
- private int empid1;
- private string name1;
- public int getempid { set { empid1 = value; } }
- public string getname { set { name1 = value; } }
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- label2.Text = empid1.ToString();
- label3.Text = name1.ToString();
- }
- }
- }
- ----------------------------------------- new page ------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace EmployeesData
- {
- public partial class Form1 : Form
- {
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- public Form1()
- {
- InitializeComponent();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- try
- {
- con.Open();
- toolStripStatusLabel1.Text = ":Connected Successfully!";
- SqlCommand cmd = con.CreateCommand();
- cmd.CommandText = "Insert into Employee (name,age,gender,email,password1,empid) values ('" + textBox2.Text + "',"+textBox3.Text+",'" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "',"+textBox1.Text+")";
- try
- {
- cmd.ExecuteNonQuery();
- toolStripStatusLabel1.Text = "Record Inserted Successfully";
- }
- catch
- {
- toolStripStatusLabel1.Text = "Querry Execution Error";
- }
- }
- catch
- {
- toolStripStatusLabel1.Text = "Connection NOT successful";
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- SqlDataAdapter sda = new SqlDataAdapter("Select * from Employee where empid="+textBox1.Text+"",con);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- textBox2.Text = dt.Rows[0][0].ToString();
- textBox3.Text = dt.Rows[0][1].ToString();
- textBox4.Text = dt.Rows[0][2].ToString();
- textBox5.Text = dt.Rows[0][3].ToString();
- textBox6.Text = dt.Rows[0][4].ToString();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from Employee where name='" + textBox2.Text + "' and empid=" + textBox1.Text + "", con);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- if (dt.Rows[0][0].ToString() == "1")
- {
- Form2 g = new Form2();
- g.getname = textBox2.Text;
- g.getempid = Int32.Parse(textBox1.Text);
- g.Show();
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- string sql = "Select * From Employee where empid='"+textBox1.Text+"'";
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- SqlDataAdapter dataadapter = new SqlDataAdapter(sql, con);
- DataTable ds = new DataTable();
- con.Open();
- dataadapter.Fill(ds);
- con.Close();
- dataGridView1.DataSource = ds;
- }
- private void button5_Click(object sender, EventArgs e)
- {
- string sql = "Select * From Employee";
- SqlConnection con = new SqlConnection(@"Data Source=PP001544;Initial Catalog=EmpProfile;Integrated Security=True");
- SqlDataAdapter dataadapter = new SqlDataAdapter(sql, con);
- DataTable ds = new DataTable();
- con.Open();
- dataadapter.Fill(ds);
- con.Close();
- dataGridView1.DataSource = ds;
- }
- private void button6_Click(object sender, EventArgs e)
- {
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = string.Format("Update Employee SET name='{1}', age='{2}', gender='{3}', email='{4}' WHERE empid='{0}'", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), textBox4.Text.Trim(), textBox5.Text.Trim());
- cmd.CommandType = CommandType.Text;
- cmd.Connection = con;
- con.Open();
- cmd.ExecuteNonQuery();
- {
- MessageBox.Show("Profile Updated Successfully!");
- con.Close();
- }
- }
- private void button7_Click(object sender, EventArgs e)
- {
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = string.Format("Delete from Employee where empid='{0}'", textBox1.Text.Trim());
- cmd.CommandType = CommandType.Text;
- cmd.Connection = con;
- con.Open();
- cmd.ExecuteNonQuery();
- {
- MessageBox.Show("Profile Updated Successfully!");
- con.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement