Home > DeveloperSection > Articles > Data Grid View

Data Grid View

ADO.Net ADO.Net 
2 Comment(s)
 6842  View(s)
Rate this:

Data Grid View

To create DataGridView first of all we need to insert DataGridView tool from toolbox.

Now, once the DataGrid is inserted we need to display data in it. To display data we need to set its data source data table.




string strConnection = "Server=abc\\SQLEXPRESs;Database=Employee;Trusted_Connection=True";

            SqlConnection con = new SqlConnection(strConnection);


            SqlDataAdapter da = new SqlDataAdapter("select * from employee", con);

            DataSet ds = new DataSet();

            da.Fill(ds, "Employee");

            DataTable dt = ds.Tables["Employee"];

            dgRecord.DataSource = dt;

//setting datasource of datagrid to a table of database ‘employee’


            catch (Exception ex)





Here dgRecord is the name of DataGrid.


By Dorababu M on   5 years ago
Is it possible to bind data by assigning the columns initially..

Binding Data by assigning the columns.

By Rohit Kesharwani on   5 years ago

You can bind columns initially by getting column names in DataTable. If you get whole data in DataTable and bind to datagridview, then it will display whole data present in DataTable. So in order to display columns initially:

1) First get column names by using select query and bind to DataTable.
2) Bind DataTable with datagridview.


Don't want to miss updates? Please click the below button!

Follow MindStick