Azure移动服务InsertAsync获取状态

本文关键字:获取 状态 InsertAsync 服务 移动 Azure | 更新日期: 2023-09-27 17:54:06

我正在插入我的Azure Mobileservice sql数据库,它工作得很好,但我想知道是否有错误,所以我可以纠正它。

如何从InsertAsync获取状态以查看它是否成功或失败?

public static MobileServiceClient MobileService = new MobileServiceClient(
  "https://YOUR-DOMAIN.azure-mobile.net/",
  "YOUR-KEY"
);
static IMobileServiceTable<Product> productTable = MobileService.GetTable<Product>();
Product product = new Product { 
  name = NPDName.Text,
  description = NPDDescription.Text,
  price = NPDPriceExkl.Text,
  tax = NPDTax.Text,
  stock = NPDStock.Text,
  available = NPDCBAvailable.Checked,
  active = true
};
productTable.InsertAsync(product);

Azure移动服务InsertAsync获取状态

我如何从InsertAsync获得状态,看看它是否成功或失败?

InsertAsync返回一个Task。如果你想知道它的状态,你需要在它上面点击await。如果失败,将传播一个异常:

public async Task InsertAsync()
{
    Product product = new Product
    { 
       name = NPDName.Text,
       description = NPDDescription.Text,
       price = NPDPriceExkl.Text,
       tax = NPDTax.Text,
       stock = NPDStock.Text,
       available = NPDCBAvailable.Checked,
       active = true
    };
    await productTable.InsertAsync(product);
}