因此我可以毫无问题地访问我的azure表,因为console.writeline显示了我想要提取的数据。 我需要做的是查询我的azure表存储,然后将结果吐出到文本框中。我的代码如下:
//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();
答案 0 :(得分:1)
我的最终目标是使用Microsoft图表工具的azure表存储来导入从Azure表存储接收的数据。
我假设您要将Microsoft Chart控件添加到Windows窗体或Web应用程序中。如果我误解了它,请告诉我你提到的Microsoft图表工具是什么。
这是一个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表存储中的数据结构
当您单击按钮并调用btnLoad_Click时,您可以获得以下结果: