如何在Azure存储帐户表中插入记录。我运行代码时应用程序关闭?我正在使用VS2017在适用于android和iOS的Xamarin跨平台上工作。我已经使用.NET c#作为后端语言发布了TODOITEM。我正在关注这个LINK! 这是我的代码(在适用于.NET的安装式Azure Configuration Manager上,它给出了错误。因此,我已将其卸载。)
Microsoft.WindowsAzure.Storage.StorageUri tableStorageUri = new Microsoft.WindowsAzure.Storage.StorageUri(new Uri("https://eg.table.core.windows.net/"));
public void adduser()
{
try
{
var accountName = "eg";
var keyValue = "SAScode";
var storageCredentials = new StorageCredentials(accountName, keyValue);
var abc= String.Format("DefaultEndpointsProtocol=https;AccountName=eg;AccountKey=KEYcode");
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(abc);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
Microsoft.WindowsAzure.Storage.Table.CloudTable table = tableClient.GetTableReference("users");
await table.CreateIfNotExistsAsync();
// Create a new new user.
Reg newuser = new Reg("regform", "uid");
newuser.username = uname.Text;
newuser.password = pword.Text;
newuser.email = uemail.Text;
newuser.firstname = fname.Text;
newuser.lastname = lname.Text;
Microsoft.WindowsAzure.Storage.Table.TableOperation insertOperation = Microsoft.WindowsAzure.Storage.Table.TableOperation.Insert(newuser);
await table.ExecuteAsync(insertOperation);
}
catch (Microsoft.WindowsAzure.Storage.StorageException ex)
{
rinfo.Text = "Storage Error";
}
catch (Exception ex)
{
rinfo2.Text = ex.StackTrace;
rinfo3.Text = ex.Message;
rinfo4.Text = ex.HelpLink;
rinfo5.Text = ex.Source;
}
//await Navigation.PushAsync(new MainPage());
}
private Microsoft.WindowsAzure.Storage.CloudStorageAccount CreateStorageAccount()
{
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount;
try
{
var accountName = "eg";
var keyValue = "SAScode";
var storageCredentials = new StorageCredentials(accountName, keyValue);
storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, null, null, tableStorageUri, null); // 6.2.2
return storageAccount;
}
catch (FormatException)
{
rinfo.Text = "format Error";
return null;
}
catch (ArgumentException)
{
rinfo.Text = "arg Error";
return null;
}
catch (Exception ex)
{
rinfo.Text = "acc Error";
return null;
}
}
private async void reg_OnClicked(object sender, EventArgs e) {adduser();}
在此先感谢。 根据杰森的建议第四次编辑 已修复