0% found this document useful (0 votes)
7 views2 pages

Sal

This document contains the code for a C# Windows Forms application that allows users to insert, update, delete, and retrieve data from an Emp table in a SQL Server database. It defines event handler methods for four buttons to perform these CRUD operations on the Emp table when the buttons are clicked. The methods open a SQL connection, construct SQL commands based on the textbox and combobox values, and execute the commands to perform the desired operation and display notification messages.

Uploaded by

salma salma
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)
7 views2 pages

Sal

This document contains the code for a C# Windows Forms application that allows users to insert, update, delete, and retrieve data from an Emp table in a SQL Server database. It defines event handler methods for four buttons to perform these CRUD operations on the Emp table when the buttons are clicked. The methods open a SQL connection, construct SQL commands based on the textbox and combobox values, and execute the commands to perform the desired operation and display notification messages.

Uploaded by

salma salma
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/ 2

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 Guna.UI2.WinForms;

namespace CC1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial


Catalog=CC1;Integrated Security=True");

private void guna2Button1_Click(object sender, EventArgs e)


{
if (guna2TextBox1.Text != "" && guna2TextBox1.Text != "" &&
guna2TextBox2.Text != "" && guna2TextBox3.Text != "" && guna2ComboBox1.Text != ""
&& guna2ComboBox2.Text != "")
{
cn.Open();
SqlCommand cmd = new SqlCommand("Insert Into Emp Values ( '" +
guna2TextBox1.Text + "' , '" + guna2TextBox2.Text + "' , '" + guna2ComboBox1.Text +
"' , '" + guna2ComboBox2.Text + "' , '" + guna2TextBox3.Text + "' , '" +
guna2DateTimePicker1.Value.ToShortDateString() + "') ", cn);
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
cn.Close();
}
else
{
MessageBox.Show("Error");
}
}

private void guna2Button2_Click(object sender, EventArgs e)


{
if (guna2TextBox1.Text != "")
{

cn.Open();
SqlCommand cmd = new SqlCommand(" select * from Emp where Mat = '"
+ guna2TextBox1.Text + "' ", cn);
SqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
guna2TextBox1.Text = r[0].ToString();
guna2TextBox2.Text = r[1].ToString();
guna2ComboBox1.Text = r[2].ToString();
guna2ComboBox2.Text = r[3].ToString();
guna2TextBox3.Text = r[4].ToString();
guna2DateTimePicker1.Value = Convert.ToDateTime(r[5]);
}

cn.Close();

}
else
{
MessageBox.Show("Please Fill all data !");
}

private void guna2Button3_Click(object sender, EventArgs e)


{
if (guna2TextBox1.Text != "" && guna2TextBox1.Text != "" &&
guna2TextBox2.Text != "" && guna2TextBox3.Text != "" && guna2ComboBox1.Text != ""
&& guna2ComboBox2.Text != "")
{
cn.Open();
SqlCommand cmd = new SqlCommand("Update Emp Set Mat = '" +
guna2TextBox1.Text + "' , Name = '" + guna2TextBox2.Text + "' , Dep = '" +
guna2ComboBox1.Text + "' , Shift = '" + guna2ComboBox2.Text + "' , Salary = '" +
guna2TextBox3.Text + "' , Date = '" +
guna2DateTimePicker1.Value.ToShortDateString() + "' Where Mat = '" +
guna2TextBox1.Text + "' ", cn);
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
cn.Close();
}
else
{
MessageBox.Show("Error");
}
}

private void guna2Button4_Click(object sender, EventArgs e)


{
if (guna2TextBox1.Text != "" )
{
cn.Open();
SqlCommand cmd = new SqlCommand("Delete from Emp Where Mat = '" +
guna2TextBox1.Text + "' ", cn);
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
cn.Close();
}
else
{
MessageBox.Show("Error");
}
}

}
}

You might also like