使用 Azure 移动服务,我可以使用以下代码将项添加到 Azure 表中:
private async void Aggi_Click(object sender, RoutedEventArgs e)
{
Bestemmye oggetto = new Bestemmye
{
Text = RicBest.Text //a textbox
};
await App.MobileService.GetTable<Bestemmye>().InsertAsync(oggetto);
}
如何读取表项?如何将它们保存到列表框中?
所以我知道这与你现在使用的完全不同。但是我也遇到了很多问题,让一切正常。这就是我现在使用的。
插入数据
IMobileServiceTable<Test> TestObj = App.MobileService.GetTable<Test>();
try
{
Test obj = new Test();
obj.test = test.Text;
obj.test1 = test1.Text;
obj.test2 = test2.Text;
obj.test3 = test3.Text;
TestObj.InsertAsync(obj);
MessageDialog msgDialog = new MessageDialog("Data Inserted!!!");
msgDialog.ShowAsync();
}
catch (Exception ex)
{
MessageDialog msgDialogError = new MessageDialog("Error : " + ex.ToString()); msgDialogError.ShowAsync();
}
要先阅读,请创建一个新的.cs文件测试.cs属性名称是您在数据库中使用的名称
public class Test
{
[JsonProperty(PropertyName = "id")]
public string test { get; set; }
[JsonProperty(PropertyName = "Name")]
public string test1 { get; set; }
[JsonProperty(PropertyName = "Title")]
public string test2 { get; set; }
[JsonProperty(PropertyName = "Description")]
public string test3 { get; set; }
}
执行的代码读取:
private async void button1_Click(object sender, RoutedEventArgs e)
{
IMobileServiceTable<Test> productTest = App.MobileService.GetTable<Test>();
// This query filters out.
MobileServiceCollection<Test, Test> products = await productTest
.Where(Test => Test.test == "Test")
.ToCollectionAsync();
lb.ItemsSource = products;
}
现在是 XAML 列表框
<ListBox
x:Name="lb">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="152">
<TextBlock Text="{Binding test}"></TextBlock>
<TextBlock Text="{Binding test1}"></TextBlock>
<TextBlock Text="{Binding test2}"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
花了我大约 50 个小时才找到这个,但它对我有用。