How to: Bind a Gauge Control to a Data Source at Runtime
The following example shows how to bind a digital gauge’s DigitalGauge.Text property to a field in the NWind database using the traditional .NET binding mechanism.
In the example, the Text property is bound to a UnitPrice field in the Products table.
To learn about the data-binding mechanism, see MSDN.
using System.Data.OleDb;
using System.Windows.Forms;
// Create a connection object.
OleDbConnection connection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\DATA\\NWIND.MDB");
// Create a data adapter.
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Products", connection);
// Create a BindingSource and populate it with data.
BindingSource bs = new BindingSource(new DataTable(), "");
adapter.Fill(bs.DataSource as DataTable);
// Bind the Text property to the UnitPrice field in the Products table.
digitalGauge1.DataBindings.Add("Text", bs, "UnitPrice");