---
title: "How to create grid view in C#,  data stored in SQL server?"  
description: "How to create grid view in C#,  data stored in SQL server?"  
author: "Abhishek Srivasatava"  
published: 2016-10-22  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/23089/how-to-create-grid-view-in-c-sharp-data-stored-in-sql-server  
category: "c#"  
tags: ["c#", "sql server"]  
reading_time: 1 minute  

---

# 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()        {            InitializeComponent();        }         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();             con3.Open();            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;            da.Fill(ds);            dataGridView1.DataSource = ds.Tables[0];         }    }}
```

## Answers

### Answer by Abhishek Srivasatava

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()        {            InitializeComponent();        }         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();             con3.Open();            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;            da.Fill(ds);            dataGridView1.DataSource = ds.Tables[0];         }    }}
```


---

Original Source: https://www.mindstick.com/interview/23089/how-to-create-grid-view-in-c-sharp-data-stored-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
