Program to work with Data Grid View Control


Design:-


  1. Create a new WindowsForms Application
  2. Create a DataGridView on it
  3. Generate EventHandler for the Default Event of the form i.e.,Load
  4. Goto Source & write the Following Code
 
using System.Data.SqlClient;
namespace FormNPQInsert
{
    public partial class FormDG1 : Form
    {
        SqlConnection Con = new SqlConnection("Server=.;User
Id=sa;Password=Admin123;DataBase=Employee");
        SqlDataAdapter Da;
        public FormDG1()
        {
            InitializeComponent();
        }

        private void FormDG1_Load(object sender, EventArgs e)
        {
            Da=new SqlDataAdapter("Select * from EmpDetails",Con);
            DataSet Ds = new DataSet();
            Da.Fill(Ds,"Table1");
            DGVSample.DataSource = Stables[0];
        }
    }
}




No comments:

Post a Comment