Users Pricing

articles

home / developersection / articles / data grid view

Data Grid View

Uttam Misra 14528 25 Jul 2010 Updated 04 Mar 2020

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

toolbox.

 Data Grid View

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.

Example
           try
            {
string strConnection= "Server=abc\\SQLEXPRESs;Database=Employee;Trusted_Connection=True";
            SqlConnection con = new SqlConnection(strConnection);
            con.Open();
            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)
            {
                MessageBox.Show(ex.Message);
            }
 
Here dgRecord is the name of DataGrid.

Data Grid View


Uttam Misra

Information Technology

More than 18 years of working experience in IT sector. We are here to serve you best.


3 Comments