我使用this tutorial以便将xamarin.forms应用程序连接到简单表格。我不能在Azure的数据添加到数据库中,我得到使用Xamarin表格轻松创建表格 - InvalidOperationException
System.InvalidOperationException
错误消息是以下
对项目的插入操作已经在队列。
在以下代码行中发生异常。
await usersTable.InsertAsync(data);
为了添加一个用户
var user = new User { Username = "username", Password = "password" };
bool x = await AddUser(user);
ADDUSER
public async Task<bool> AddUser(User user)
{
try
{
await usersTable.InsertAsync(user);
await SyncUsers();
return true;
}
catch (Exception x)
{
await new MessageDialog(x.Message.ToString()).ShowAsync();
return false;
}
}
SyncUsers()
public async Task SyncUsers()
{
await usersTable.PullAsync("users", usersTable.CreateQuery());
await client.SyncContext.PushAsync();
}
其中
IMobileServiceSyncTable<User> usersTable;
MobileServiceClient client = new MobileServiceClient("url");
初始化
var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "DBNAME.db");
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<User>();
await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
usersTable = client.GetSyncTable<User>();
你可以分享你的其他代码吗?谢谢!但是,我认为这可能是因为该项目已添加到您的表格中。提醒一下,我没有设置Id的值。 – mindOfAi