C#.Net Simple Insert Update Delete to SQL

 C#.Net Simple Insert Update Delete to SQL


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 WindowsFormsApplication2

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=ICTV34;Initial Catalog=ICTPT21;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO jcot VALUES ('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"')", con);

            cmd.ExecuteNonQuery();

            MessageBox.Show("Done");

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=ICTV34;Initial Catalog=ICTPT21;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("UPDATE jcot SET name= '" + textBox2.Text + "', address='" + textBox3.Text + "', mobile='" + textBox4.Text + "',email='" + textBox5.Text + "' WHERE regno='" + textBox1.Text + "'", con);

            cmd.ExecuteNonQuery();

            MessageBox.Show("Update Done");

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=ICTV34;Initial Catalog=ICTPT21;Integrated Security=True");

            con.Open();

            SqlCommand cmd = new SqlCommand("DELETE FROM jcot WHERE regno='" + textBox1.Text + "'", con);

            cmd.ExecuteNonQuery();

            MessageBox.Show("Deletion Done");

        }

 

        private void label1_Click(object sender, EventArgs e)

        {

 

        }

    }

}

 


Post a Comment

0 Comments