windowsforms-18271-controls-and-libraries-gauges-examples-how-to-bind-a-gauge-control-to-a-data-source-at-runtime.md
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");
Imports System.Data.OleDb
Imports System.Windows.Forms
' Create a connection object.
Private connection As OleDbConnection = _
New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DATA\NWIND.MDB")
' Create a data adapter.
Private adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Products", connection)
' Create a BindingSource and populate it with data.
Private bs As BindingSource = New BindingSource(New DataTable(), "")
adapter.Fill(TryCast(bs.DataSource, DataTable))
' Bind the Text property to the UnitPrice field in the Products table.
digitalGauge1.DataBindings.Add("Text", bs, "UnitPrice")