Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将Windows Azure数据库连接到Microsoft Visual Studio 2012-Windows Phone 8项目_C#_Wpf_Visual Studio 2012_Azure_Windows Phone 8 - Fatal编程技术网

C# 如何将Windows Azure数据库连接到Microsoft Visual Studio 2012-Windows Phone 8项目

C# 如何将Windows Azure数据库连接到Microsoft Visual Studio 2012-Windows Phone 8项目,c#,wpf,visual-studio-2012,azure,windows-phone-8,C#,Wpf,Visual Studio 2012,Azure,Windows Phone 8,我是一名计算机科学专业的大四学生,正在尝试开发一款Windows8手机应用程序,我对这类开发非常陌生。 我正在使用带有移动服务和数据库连接的Windows Azure帐户连接到Visual Studio 2012 我试图允许用户创建一个帐户来使用我的应用程序,但是当他们输入任何详细信息时,他们不会保存到数据库中的表中。当我运行代码并按下“注册”按钮时,出现以下调试错误: “应用程序\u未处理异常” 下面是我的代码的样子 这来自CreateAccount.xaml.cs文件: using

我是一名计算机科学专业的大四学生,正在尝试开发一款Windows8手机应用程序,我对这类开发非常陌生。 我正在使用带有移动服务和数据库连接的Windows Azure帐户连接到Visual Studio 2012

我试图允许用户创建一个帐户来使用我的应用程序,但是当他们输入任何详细信息时,他们不会保存到数据库中的表中。当我运行代码并按下“注册”按钮时,出现以下调试错误:

“应用程序\u未处理异常”

下面是我的代码的样子

这来自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;
        }
    }
}
    }
    // 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”


任何帮助都将不胜感激。

如果您尚未解决此问题,请放置一个断点,并告诉我您在哪一行代码处遇到异常?