Ready to get started?

Download a free trial of the Azure Data Lake Storage Data Provider to get started:

 Download Now

Learn more:

Azure Data Lake Storage Icon Azure Data Lake Storage ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Azure Data Lake Storage.

DataBind Charts to Azure Data Lake Storage Data



Use the standard ADO.NET procedures for databinding to provide bidirectional access to Azure Data Lake Storage data from controls in the Visual Studio toolbox. This article demonstrates a graphical approach using wizards in Visual Studio, as well as how to databind with only a few lines of code.

DataBinding facilitates two-way interaction with data through UI controls. Using the CData ADO.NET Provider for Azure Data Lake Storage streamlines the process of binding Azure Data Lake Storage data to Windows Forms and Web controls within Visual Studio. In this article, we will demonstrate using wizards to establish a binding between Azure Data Lake Storage 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.

DataBind to a Chart

DataBinding consists of three steps: Instantiate the control, configure the data source, and databind.

Configure the Connection and Select Database Objects

To create a chart control and establish a connection to Azure Data Lake Storage, follow the steps outlined below using the Data Source Configuration Wizard. Within the wizard, you'll have the option to choose the specific Azure Data Lake Storage entities you wish to bind to.

  1. In a Windows Forms project, drag and drop a Chart control from the toolbox to the form. In the Data section of the Chart properties, select DataSource and then select Add Project Data Source from the menu.
  2. In the Data Source Configuration Wizard that appears, select Database -> Dataset.
  3. In the Choose Your Data Connection step, click New Connection.
  4. In the Add Connection dialog, click Change to select the CData Azure Data Lake Storage Data Source.

    Below is a typical connection string:

    Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=GETANDREFRESH

    Authenticating to a Gen 1 DataLakeStore Account

    Gen 1 uses OAuth 2.0 in Azure AD for authentication.

    For this, an Active Directory web application is required. You can create one as follows:

    1. Sign in to your Azure Account through the .
    2. Select "Azure Active Directory".
    3. Select "App registrations".
    4. Select "New application registration".
    5. Provide a name and URL for the application. Select Web app for the type of application you want to create.
    6. Select "Required permissions" and change the required permissions for this app. At a minimum, "Azure Data Lake" and "Windows Azure Service Management API" are required.
    7. Select "Key" and generate a new key. Add a description, a duration, and take note of the generated key. You won't be able to see it again.

    To authenticate against a Gen 1 DataLakeStore account, the following properties are required:

    • Schema: Set this to ADLSGen1.
    • Account: Set this to the name of the account.
    • OAuthClientId: Set this to the application Id of the app you created.
    • OAuthClientSecret: Set this to the key generated for the app you created.
    • TenantId: Set this to the tenant Id. See the property for more information on how to acquire this.
    • Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.

    Authenticating to a Gen 2 DataLakeStore Account

    To authenticate against a Gen 2 DataLakeStore account, the following properties are required:

    • Schema: Set this to ADLSGen2.
    • Account: Set this to the name of the account.
    • FileSystem: Set this to the file system which will be used for this account.
    • AccessKey: Set this to the access key which will be used to authenticate the calls to the API. See the property for more information on how to acquire this.
    • Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.

    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.

  5. Choose the database objects you want to work with. This example uses the Resources table.

DataBind

After adding the data source and selecting database objects, you can bind the objects to the chart. This example assigns the x-axis to FullPath and the y-axis to Permission.

  1. In the Chart properties, click the button in the Series property to open the Series Collection Editor.
  2. In the Series properties, select the columns you want for the x- and y-axes: Select columns from the menu in the XValueMember and YValueMember properties.

The chart is now databound to the Azure Data Lake Storage data. Run the chart to display the current data.

Code Walk-through

DataBinding to Azure Data Lake Storage data requires only a few lines of code and can be completed in three easy steps.

  1. Connect to Azure Data Lake Storage.
  2. Create the ADLSDataAdapter to execute the query and create a DataSet to be filled with its results.
  3. DataBind the result set to the chart.

Below is the complete code:

ADLSConnection conn = new ADLSConnection("Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=GETANDREFRESH"); ADLSCommand comm = new ADLSCommand("SELECT FullPath, Permission FROM Resources WHERE Type = 'FILE'", conn); ADLSDataAdapter da = new ADLSDataAdapter(comm); DataSet dataset = new DataSet(); da.Fill(dataset); chart1.DataSource = dataset; chart1.Series[0].XValueMember = "FullPath"; chart1.Series[0].YValueMembers = "Permission"; // Insert code for additional chart formatting here. chart1.DataBind();