DataGridView Binding - OLEDB dataset
The DataGridView provides the capability to exhibit data through Bound mode, unbound mode, and Virtual mode. For beginners, investigating into basic data-binding scenarios proves to be the most straightforward way to use the DataGridView control's functionality.
How to bind an OLEDB dataset
When a data source is specified for the DataGridView, it conveniently generates columns automatically, tailored to the data types within the source, making the setup process seamless and effortless. By intelligently analyzing the data source, the DataGridView constructs an appropriate column structure, eliminating the need for manual column creation.
The following C# program shows how to bind an OLEDB dataset to a DataGridView.
Full Source C#
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=your .mdb file;";
string sql = "SELECT * FROM Authors";
OleDbConnection connection = new OleDbConnection(connetionString);
OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Authors_table");
connection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Authors_table";
}
}
}
Related Topics
- C# DataGridView Binding - SQL Server dataset
- C# DataGridView Sorting and Filtering
- C# DataGridView Add Columns and Rows
- C# DataGridView Hide Columns and Rows
- C# DataGridView Read Only Columns and Rows
- Add Button to C# DataGridView
- Add CheckBox to C# DataGridView
- Add ComboBox to C# DataGridView
- Add Image to C# DataGridView
- Add ViewLink to C# DataGridView
- C# DataGridView Paging
- C# DataGridView Formatting
- C# DataGridView Template
- C# DataGridView Printing
- C# DataGridView Export to Excel
- C# DataGridView Loading data from Excel
- C# DataGridView Database Operations
- Delete row from datagridview by right click
- DataGridView Autocomplete TextBox in C#