In this short article, I will write a simple code to Insert, update, delete, and Retrieve operations. Open the new project and then write the following code:

       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 for using sqlserver components                    
    namespace InsertApp 
    { 
        public partial class Form1 : Form 
        { 
                          public Form1() 
            { 
                InitializeComponent(); 
            } 
                  private void Form1_Load(object sender, EventArgs e) 
            { 
                Getgrid(); 
            }                  
  public void Getgrid() 
            { 
                SqlConnection con = new SqlConnection("Data Source=SQLEXPRESS; Initial Catalog=SQLDATABASE; Integrated Security=SSPI "); 
                con.Open(); 
                SqlDataAdapter da = new SqlDataAdapter("select * from employee", con); 
                DataSet ds = new DataSet(); 
                da.Fill(ds); 
                dataGridView1.DataSource = ds.Tables[0]; 
           }        
            // Method for Insert the values 
            private void btnInsert_Click(object sender, EventArgs e)  
            { 
                SqlConnection con=new SqlConnection("Data Source=SQLEXPRESS; Initial Catalog=SQLDATABASE; Integrated Security=SSPI "); 
                con.Open();        
                    SqlCommand cmd = new SqlCommand("Insert into employee values('" + txtId.Text + "','" + txtName.Text + "','" + txtDesigid.Text + "','" + txtEmploc.Text + "')", con); 
                    int check = cmd.ExecuteNonQuery(); 
                    if (check > 0) 
                    { 
                        MessageBox.Show("Inserted"); 
                    } 
                    else 
                    { 
                        MessageBox.Show("Not- Inserted"); 
                    }                      
                    cmd.Dispose(); 
                    con.Close(); 
                    Getgrid();                    
            }        
            // Method for Update the values 
           private void btnUpdate_Click(object sender, EventArgs e) 
            { 
                SqlConnection con = new SqlConnection("Data Source=SQLEXPRESS; Initial Catalog=SQLDATABASE; Integrated Security=SSPI "); 
                con.Open();                    
                    SqlCommand cmd = new SqlCommand("update employee set emp_id='" + txtId.Text + "', emp_name='" + txtName.Text + "',desig_id='" + txtDesigid.Text + "',emp_location='" + txtEmploc.Text + "' where emp_id='"+txtId.Text+"'", con); 
                    cmd.ExecuteNonQuery(); 
                    MessageBox.Show("updated"); 
                    cmd.Dispose(); 
                    con.Close(); 
                    Getgrid(); 
            }        
            // Method for Delete the values 
            private void btnDelete_Click(object sender, EventArgs e) 
            { 
                SqlConnection con = new SqlConnection("Data Source=SQLEXPRESS; Initial Catalog=SQLDATABASE; Integrated Security=SSPI "); 
                con.Open();       
                SqlCommand cmd = new SqlCommand("delete from employee where emp_id='" + txtId.Text + "'", con); 
                cmd.ExecuteNonQuery(); 
                MessageBox.Show("deleted"); 
                cmd.Dispose(); 
                con.Close(); 
                Getgrid(); 
            }        
            // Method for Retrieve the values 
            private void btnRetrieve_Click(object sender, EventArgs e) 
            { 
                SqlConnection con = new SqlConnection("Data Source=SQLEXPRESS; Initial Catalog=SQLDATABASE; Integrated Security=SSPI "); 
                con.Open(); 
                      SqlCommand cmd = new SqlCommand("select * from employee where emp_id='" + txtId.Text + "'", con); 
                SqlDataReader dr = cmd.ExecuteReader(); 
                if (dr.Read()) 
                { 
                    txtId.Text = dr[0].ToString(); 
                    txtName.Text = dr[1].ToString(); 
                    txtDesigid.Text = dr[2].ToString(); 
                    txtEmploc.Text = dr[3].ToString(); 
                } 
            }        
            // Method for Clear values in textbox 
            private void btnClear_Click(object sender, EventArgs e) 
            { 
                clearmethod();             // calling clear method 
            }        
            public void clearmethod() 
            { 
                txtId.Text = ""; 
                txtName.Text = ""; 
                txtDesigid.Text = ""; 
                txtEmploc.Text = ""; 
            }      
        } 
   } 
Happy coding! 

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.