You are on page 1of 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