如何从Windows Phone 8上的Azure表中读取数据

时间:2013-02-20 22:14:01

标签: azure windows-phone-8

这是Windows Phone 8(Azure)应用程序。我尝试将整张图片表格添加到PictureList。但我只有空行(行数与Azure数据库中的行数相同,因此它可以正确同步,但没有值)。

public class PicturesTableItem
{
    public int Id { get; set; }

    [DataMember(Name = "name")]
    public string Name { get; set; }

    [DataMember(Name = "category")]
    public string Category { get; set; }

    [DataMember(Name = "address")]
    public string Address { get; set; }

}

public partial class MainPage : PhoneApplicationPage
{
    private MobileServiceCollectionView<PicturesTableItem> PicturesItems;
    private IMobileServiceTable<PicturesTableItem> PicturesTable = App.MobileService.GetTable<PicturesTableItem>();
    private List<PicturesTableItem> PictureList = new List<PicturesTableItem>();

    // Constructor
    public MainPage()
    {
        InitializeComponent();

        // Set the data context of the listbox control to the sample data
        DataContext = App.ViewModel;

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }

    private void RefreshPicturesTableItems()
    {
        PicturesItems = PicturesTable.ToCollectionView();
    }

    /*
     * Override
     */
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        RefreshPicturesTableItems();
    }
}

我想以这种方式展示它

string temp = "";
foreach (var element in PictureList)
{
    temp = temp + element.Address.ToString()+"\n";
}
MessageBox.Show(temp.ToString());

你能告诉我怎么做得好吗?

我不能去

PictureList = PicturesTable.ToListAsync();

1 个答案:

答案 0 :(得分:1)

确保数据库中的名称与DataMember名称相同。就我而言,这是解决同样问题的方法。