C# DataGridView Binding - SQL Server dataset
The DataGridView can display data in Bound mode, unbound mode and Virtual mode . Bound mode is suitable for managing data using automatic interaction with the data store. One very common use of the DataGridView control is binding to a table in a database. Unbound mode is suitable for displaying relatively small amounts of data that you manage programmatically. Virtual mode gives you a higher degree of control by allowing you to wait until a cell is actually being displayed to provide the value it will contain.
The following C# program shows how to bind a SQL Server dataset to a DataGridView.
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True";
string sql = "SELECT * FROM Authors";
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Authors_table";
C# DataGridView - Related Contents