Database Connectivity
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\kisho\OneDrive\Documents\Empl
oyee.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand ("Insert into Employee_Table
values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text +"','"+textBox4
.Text+"','"+comboBox1 .Text +"')",con);
cmd.ExecuteNonQuery();
MessageBox .Show("Insert data successfully");
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand ("update Employee_Table SET Employee_Name
= '"+textBox2.Text+"',Address = '"+textBox3 .Text +"', salary ='"+textBox4 .Text +"'
where Employee_Id='"+textBox1 .Text+"'",con);
cmd.ExecuteNonQuery();
MessageBox.Show("Update data successfully");
con.Close();
}
private void button4_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Delete Employee_Table where Employee_Id='"
+textBox1.Text + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Delete data successfully");
con.Close();
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = "";
}
}
}
Comments
Post a Comment