![]() |
VOOZH | about |
DataBinding facilitates two-way interaction with data through UI controls. Using the CData ADO.NET Provider for AlloyDB streamlines the process of binding AlloyDB data to Windows Forms and Web controls within Visual Studio. In this article, we will demonstrate using wizards to establish a binding between AlloyDB data and a chart that dynamically updates. Additionally, the code walk-through section will guide you through the creation of a chart using just 10 lines of code.
DataBinding to a Chart consists of three steps: Instantiate the control, configure the data source, and databind.
To create a chart control and establish a connection to AlloyDB, follow the steps outlined below using the Data Source Configuration Wizard. Within the wizard, you'll have the option to choose the specific AlloyDB entities you wish to bind to.
In the Add Connection dialog, click Change to select the CData AlloyDB Data Source.
Below is a typical connection string:
User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432
The following connection properties are usually required in order to connect to AlloyDB.
You can also optionally set the following:
Standard authentication (using the user/password combination supplied earlier) is the default form of authentication.
No further action is required to leverage Standard Authentication to connect.
There are additional methods of authentication available which must be enabled in the pg_hba.conf file on the AlloyDB server.
Find instructions about authentication setup on the AlloyDB Server here.
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to md5.
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to scram-sha-256.
The authentication with Kerberos is initiated by AlloyDB Server when the β is trying to connect to it. You should set up Kerberos on the AlloyDB Server to activate this authentication method. Once you have Kerberos authentication set up on the AlloyDB Server, see the Kerberos section of the help documentation for details on how to authenticate with Kerberos.
When you configure the connection, you may also want to set the Max Rows connection property. This will limit the number of rows returned, which is especially helpful for improving performance when designing reports and visualizations.
π Connection properties for the selected data source in the Add Connection dialog. (Salesforce is shown.)After adding the data source and selecting database objects, you can bind the objects to the chart. This example assigns the x-axis to ShipName and the y-axis to ShipCity.
The chart is now databound to the AlloyDB data. Run the chart to display the current data.
π The chart, filled with data at run time.
DataBinding to AlloyDB data requires only a few lines of code and can be completed in three easy steps.
Below is the complete code:
AlloyDBConnection conn = new AlloyDBConnection("User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432");
AlloyDBCommand comm = new AlloyDBCommand("SELECT ShipName, ShipCity FROM Orders WHERE ShipCountry = 'USA'", conn);
AlloyDBDataAdapter da = new AlloyDBDataAdapter(comm);
DataSet dataset = new DataSet();
da.Fill(dataset);
chart1.DataSource = dataset;
chart1.Series[0].XValueMember = "ShipName";
chart1.Series[0].YValueMembers = "ShipCity";
// Insert code for additional chart formatting here.
chart1.DataBind();
Download a free trial of the AlloyDB Data Provider to get started:
Download NowLearn more:
π AlloyDB IconRapidly create and deploy powerful .NET applications that integrate with AlloyDB.