C# 将文本框值设置为 Table 来自 Azure Table 存储的查询

C# Set Textbox Value to Table Query from Azure Table Storage

所以我可以毫无问题地访问我的 azure table,因为 console.writeline 显示了我要提取的数据。 我需要做的是查询我的 azure table 存储,然后将结果输出到文本框中。我的代码如下:

               //start of code
               CloudStorageAccount storageAccount =
               CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=telephony;AccountKey=RandomKeyhere);
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("TelephonyIssueLog");
        await table.CreateIfNotExistsAsync();

        //This is the code I'm having troubles with.
        TableQuery<IssueEntity> query = new TableQuery<IssueEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Issues"));
        textBox1.Text = table.ExecuteQuery(query).ToString();

My ultimate goal is to use azure table storage with Microsoft Chart Tools to import the data received from Azure table Storage.

我假设您想将 Microsoft Chart 控件添加到您的 Windows 表单或 Web 应用程序中。如果我理解有误,请告诉我你说的Microsoft Chart Tools是什么。

这里有一个 Windows 表单应用程序,让您更好地理解如何将查询的数据放入 Basic Chart.

DemoForm.cs

private void btnLoad_Click(object sender, EventArgs e)
{
    GenerateChart(this.DemoChart, LoadData());
}

/// <summary>
/// Load data from Azure Table
/// </summary>
/// <returns></returns>
private IList<MetricEntity> LoadData()
{
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("BruceChenStorageConnectionString"));
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    CloudTable cloudTable = tableClient.GetTableReference("TelephonyIssueLog");
    cloudTable.CreateIfNotExists();
    TableQuery<MetricEntity> query = new TableQuery<MetricEntity>()
        .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Issues"));
    return cloudTable.ExecuteQuery(query).ToList();
}

/// <summary>
/// Generate the column chart with the specified data source
/// </summary>
/// <param name="chart"></param>
/// <param name="dataItems"></param>
private void GenerateChart(Chart chart, IEnumerable<MetricEntity> dataItems)
{
    chart.Series.Clear();
    chart.Titles.Add(
        new Title("Demo Chart for loading data from Azure Table"));
    List<string> xValues = new List<string>() { "MetricA", "MetricB", "MetricC" };
    foreach (var item in dataItems)
    {
        Series series = new Series() { Name = item.UserName };
        series.ChartType = SeriesChartType.Column;
        series.Points.DataBindXY(xValues, new List<int>() {
          item.MetricA,
          item.MetricB,
          item.MetricC});
        chart.Series.Add(series);
    }
}

MetricEntity.cs

public class MetricEntity : TableEntity
{
    public MetricEntity(string partitionKey, string rowKey)
    {
        this.PartitionKey = partitionKey;
        this.RowKey = rowKey;
    }
    public MetricEntity() { }
    public int MetricA { get; set; }
    public int MetricB { get; set; }
    public int MetricC { get; set; }
    public string UserName { get; set; }
}

Azure 中的数据结构Table 存储

当你点击按钮并调用btnLoad_Click时,你会得到如下结果: