Advertise with us

How to create grid view in C#, data stored in SQL server?

Posted by  Abhishek Srivasatava
 883  View(s)
Rate this:
  1. How to create grid view in C#, data stored in SQL server?

    Here is the most basic and easy way to represent data in the grid view form.

    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;
    using System.Data.SqlTypes;
    namespace FormsApplication1
        public partial class Form4 : Form
            public Form4()
            public void fill()
                SqlConnection con3 = new SqlConnection();
                con3.ConnectionString = (@"Data Source=msclient-012\sqlexpress;Initial Catalog=testing_st;User ID=sa;Password=mindstick");
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand("select A.Enrollment_number,A.Student_name,A.Father_Name,A.Mother_Name,A.Sex,A.Permanent_Add,A.Permanent_State,B.Subject_Maths,B.Subject_Physics,B.Subject_Chemistry,B.Subject_English,B.Subject_Hindi,B.Subject_Social,B.class FROM Std_Details A,Std_Opt_Sub B where A.Enrollment_number = B.Enrollment_number", con3);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                dataGridView1.DataSource = ds.Tables[0];



      Modified On Mar-29-2018 12:07:03 AM