Page Rank

Subscribe

Categories

Recent posts

Alexa Rank

Create DataTable at runtime and bind to DataGridView in C#


  • This topic explains how to create DataTable at runtime and bind it to the DataGridView in C#.
  • For this example in C#, we need only a DataGridView Control and also need to declare DataTable in C# form.

Working of DataTableCreate DataTable at runtime and bind to DataGridView in C#

  • A DataSet is made up of a collection of Tables, relations and constraints.
  • DataTable is used to represent Tables in DataSet.
  • The DataTable class is a member of System.Data namespace.
  • A DataTable represents one table of in-memory relation data.
  • You can access the collections of tables in DataSet through the table property of the DataSet object.
  • Datatable can be created and used independently.
  • DataTable can be used by other .NET Framework objects.

Example to create a DataTable in C#

Example to create DataTable by adding it to the Table collections of DataSet

DataGridView in C#Create DataTable at runtime and bind to DataGridView in C#

  • The DataGridView in C# control provides a customizable table for displaying data.
  • DataGridView in C# control is designed to be a complete solution for displaying tabular data with Windows Forms.
  • DataGridView class in C# allows us to customization of cells, rows, columns, and borders through the use of its properties
  • Each cell within the DataGridView control in C# can have its own style, such as text format, background color, foreground color, font etc.
  • All cells derive from the DataGridViewCell base class.

Create DataTable at runtime and bind to DataGridView in C#Working

  • When a form loads, it creates a datatable dt and add columns using Add method(Columns.Add).
  • Then add rows using Add method (Rows.Add).
  • Finally assign the values of the datatable to the datagrid using DataSource property of dataGridView.

Create DataTable at runtime and bind to DataGridView in C#Complete Code

Create DataTable at runtime and bind to DataGridView in C#

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">