简体   繁体   English

c#Windows Azure移动服务插入/读取数据

[英]c# Windows Azure Mobile Services insert/read data

I'm creating a Windows 8 Store App (c#) using Windows Azure Mobile Services to store my data. 我正在使用Windows Azure移动服务创建一个Windows 8 Store App(c#)来存储我的数据。 I can successfully add data to the Table (ToDoItem) but got problems with reading it. 我可以成功将数据添加到表(ToDoItem),但是在读取数据时遇到问题。

To add Data: 要添加数据:

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

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

    [DataMember(Name = "Private")]
    public bool Private { get; set; }

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

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

public sealed partial class ViewItems : Page
{

    private ObservableCollection<TodoItem> items;
    private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();

    private async void InsertTodoItem(TodoItem todoItem)
    {
        await todoTable.InsertAsync(todoItem);
    }

    private void ButtonSave_Click(object sender, RoutedEventArgs e)
    {
        var todoItem = new TodoItem { Text = Ploeg1.Text, Team1 = Ploeg1.Text, Team2 = Ploeg2.Text};
        InsertTodoItem(todoItem);
    }
}

So this piece of code works! 因此,这段代码有效! Now the problem: I want to read the data from the Mobile Service in another blank page: 现在的问题是:我想从另一个空白页的移动服务中读取数据:

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

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

    [DataMember(Name = "Private")]
    public bool Private { get; set; }

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

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

public sealed partial class gamestore : Page
{
    private ObservableCollection<TodoItem> items;
    private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();

    private void ButtonRefresh_Click(object sender, RoutedEventArgs e)
    {
       RefreshTodoItems();
    }

    private async void RefreshTodoItems()
    {
        var results = await todoTable2
            .Where(todoItem => todoItem.Private == false)
            .ToListAsync();

        items = new ObservableCollection<TodoItem>(results);
        ListItems.ItemsSource = items;
    }
}

I have some Ambiguity errors with this. 我对此有一些歧义性错误。 I know I'm using the same names but those are my column names. 我知道我使用的是相同的名称,但这些是我的列名称。 How can I make this work so it would be able to read the saved data on another page?? 我该如何进行这项工作,以便能够读取另一页上保存的数据?

Fixed the problem! 解决了问题! Changed a few names 改了几个名字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM