我是一位正在嘗試開發Windows 8電話應用程序的最後一年計算機科學專業的學生,我對這種類型的開發非常陌生。我正在使用移動服務和數據庫連接的Windows Azure帳戶連接到Visual Studio 2012.將Windows Azure連接到Microsoft Visual Studio 2012 - windows phone 8
我試圖讓用戶創建一個帳戶來使用我的應用程序,但是當他們輸入任何細節時他們不是被保存到數據庫中的表格中。
「Application_UnhandledException」
下面是我的代碼如下所示:當我運行我的代碼,按註冊按鈕我收到以下錯誤調試。
這是從CreateAccount.xaml.cs文件:
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 Microsoft.WindowsAzure.MobileServices;
using Newtonsoft.Json;
namespace IME.Miscellaneous
{
public class accountDetails
{
// Setting up the items for inclusion in the createAccount table
public string Id { get; set; }
[JsonProperty(PropertyName = "userpassword")]
public string Password { get; set; }
[JsonProperty(PropertyName = "securityQuestion1")]
public string SecurityQuestion1 { get; set; }
[JsonProperty(PropertyName = "securityQuestion2")]
public string SecurityQuestion2 { get; set; }
[JsonProperty(PropertyName = "securityQuestion3")]
public string SecurityQuestion3 { get; set; }
[JsonProperty(PropertyName = "answer1")]
public string SecurityAnswer1 { get; set; }
[JsonProperty(PropertyName = "answer2")]
public string SecurityAnswer2 { get; set; }
[JsonProperty(PropertyName = "answer3")]
public string SecurityAnswer3 { get; set; }
}
public partial class CreateAccount : PhoneApplicationPage
{
private MobileServiceCollection<accountDetails, accountDetails> items;
private IMobileServiceTable<accountDetails> accountTable = App.MobileService.GetTable<accountDetails>();
public CreateAccount()
{
InitializeComponent();
}
private async void InsertAccountInfo(accountDetails accountDetailsItem)
{
// This code inserts a new item into the database. When the operation completes
// and Mobile Services has assigned an Id, the item is added
await accountTable.InsertAsync(accountDetailsItem);
items.Add(accountDetailsItem);
}
private async void RefreshAccountInfo()
{
// This code refreshes the entries in the list view be querying the createAccount table.
try
{
items = await accountTable
.Where(accountDetailsItem => accountDetailsItem.Password == "")
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException e)
{
MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
}
}
private void Register_Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
// Brings the user to the Home hub page
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
// When button is clicked the accountDetails table is updated with the password
//var user = new accountDetails { Id = ID_textbox.Text, Password = Password_Text.Password, SecurityQuestion1 = Security_Question_1.Text, SecurityQuestion2 = Security_Question_2.Text,
// SecurityQuestion3 = Security_Question_3.Text, SecurityAnswer1 = Security_Question_1_Answer.Text, SecurityAnswer2 = Security_Question_2_Answer.Text,
// SecurityAnswer3 = Security_Question_3_Answer.Text};
// InsertAccountInfo(user);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
RefreshAccountInfo();
}
private void Security_Question_1_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerOne = (TextBox)sender;
securityAnswerOne.Text = string.Empty;
securityAnswerOne.GotFocus -= Security_Question_1_Answer_GotFocus;
}
private void Security_Question_2_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerTwo = (TextBox)sender;
securityAnswerTwo.Text = string.Empty;
securityAnswerTwo.GotFocus -= Security_Question_2_Answer_GotFocus;
}
private void Security_Question_3_Answer_GotFocus(object sender, RoutedEventArgs e)
{
// Sets the textbox to empty when the user clicks on it
TextBox securityAnswerThree = (TextBox)sender;
securityAnswerThree.Text = string.Empty;
securityAnswerThree.GotFocus -= Security_Question_3_Answer_GotFocus;
}
private void Security_Question_3_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerThree = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
{
securityAnswerThree.Text = "Please Enter an answer";
securityAnswerThree.LostFocus -= Security_Question_3_Answer_LostFocus;
}
}
private void Security_Question_2_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerTwo = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_2_Answer.Text))
{
securityAnswerTwo.Text = "Please Enter an answer";
securityAnswerTwo.LostFocus -= Security_Question_2_Answer_LostFocus;
}
}
private void Security_Question_1_Answer_LostFocus(object sender, RoutedEventArgs e)
{
TextBox securityAnswerOne = (TextBox)sender;
if (String.IsNullOrEmpty(Security_Question_3_Answer.Text))
{
securityAnswerOne.Text = "Please Enter an answer";
securityAnswerOne.LostFocus -= Security_Question_3_Answer_LostFocus;
}
}
}
}
這是從App.xaml.cs文件:
// Creating account details table
public class accountDetails
{
public int id { get; set; }
public string userpassword { get; set; }
public string securityQuestion1 { get; set; }
public string securityQuestion2 { get; set; }
public string securityQuestion3 { get; set; }
public string answer1 { get; set; }
public string answer2 { get; set; }
public string answer3 { get; set; }
public accountDetails(string p, string sq1, string sq2, string sq3, string a1, string a2, string a3)
{
// Creating the constructor
userpassword = p;
securityQuestion1 = sq1;
securityQuestion2 = sq2;
securityQuestion3 = sq3;
answer1 = a1;
answer2 = a2;
answer3 = a3;
}
}
在數據庫中的表被稱爲 「的createAccount」也。
任何幫助將不勝感激。