2013-12-08 40 views
0

我是一位正在尝试开发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”也。

任何帮助将不胜感激。

回答

0

你应该把一些更多的错误处理放在 - 它不清楚你的错误是发生在Register_Button_Tap事件处理程序还是在RefreshAccountInfo方法中。

另外,你说数据库中的表被称为“CreateAccount”,但你的移动服务引用使用一个名为“accountDetails”的表。

相关问题