items = await memberTable.ToCollectionAsync(); var insertItem = new MyMember { Name = "Win", Email = "[email protected]" }; await memberTable.InsertAsync(insertItem); items.Add(insertItem); lblStatus.Text = "Insert Data Successfully.";
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; using myPhoneApp.Resources; using Microsoft.WindowsAzure.MobileServices; using Newtonsoft.Json; namespace myPhoneApp { public class MyMember { public int Id { get; set; } [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "email")] public string Email { get; set; } } public partial class MainPage : PhoneApplicationPage { private MobileServiceCollection<MyMember, MyMember> items; private IMobileServiceTable<MyMember> memberTable = App.MobileService.GetTable<MyMember>(); // Constructor public MainPage() { InitializeComponent(); } private async void InsertMemberItem() { try { items = await memberTable.ToCollectionAsync(); var insertItem = new MyMember { Name = "Win", Email = "[email protected]" }; await memberTable.InsertAsync(insertItem); items.Add(insertItem); lblStatus.Text = "Insert Data Successfully."; } catch (MobileServiceInvalidOperationException e) { lblStatus.Text = "Insert Data Failed! Error " + e.Message; } } protected override void OnNavigatedTo(NavigationEventArgs e) { InsertMemberItem(); } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท