Insert into a Table using Windows Forms Application

Output Screen Shots

Fig1: Enter data and Submit

Fig1:Scn Shot of sample DB after insert operation

Source 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 WinConnectedApp
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {

            SqlConnection con = new SqlConnection();
            // Create a connection object
            con.ConnectionString = @"Data source=USERS35\SQLExpress;initial catalog = training1;integrated security =true";
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "insert into employee values(@eid,@efname,@elname,@eloc,@sal)";
            cmd.Parameters.AddWithValue("@eid", txtEmpId.Text);
            cmd.Parameters.AddWithValue("@efname", txtFirstName.Text);
            cmd.Parameters.AddWithValue("@elname", txtLastName.Text);
            cmd.Parameters.AddWithValue("@eloc", txtloc.Text);
            cmd.Parameters.AddWithValue("@sal", txtSal.Text);


            //0     1       2       3       4
            try
            {
                con.Open();//establishes phy link between App and DB
                cmd.ExecuteNonQuery();
               
                MessageBox.Show("Rows have been added");


            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
    }
}