尝试从sqlite数据库中读取数据时出现System.NotSupportedException

时间:2017-07-04 04:27:39

标签: c# sqlite windows-phone-8.1

我是c#的新手。在尝试从数据库中检索数据时,我在第2页遇到以下错误。

SQLite.Net.DLL中发生了'System.NotSupportedException'类型的异常但未在用户代码中处理

其他信息:不知道如何阅读Windows.UI.Xaml.Controls.TextBox。

这是我的代码(第1页)

public sealed partial class MainPage : Page
{
    string path;
    SQLite.Net.SQLiteConnection conn;//this is used to create connection


    public MainPage()
    {
      //  TestAsyncAwaitMethods();
        this.InitializeComponent();

        /// this is to create the database.
        path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
        conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);
        conn.CreateTable<Customer>();//to create table
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.
    /// This parameter is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        // TODO: Prepare page for display here.

        // TODO: If your application contains multiple pages, ensure that you are
        // handling the hardware Back button by registering for the
        // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
        // If you are using the NavigationHelper provided by some templates,
        // this event is handled for you.
    }

    /// <summary>
    /// This method will add the data in to SQL Database.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        var s = conn.Insert(new Customer()
        {
            Name = txtName.Text,
            Age = txtAge.Text,
            Number = txtPhn_no.Text
        });

    }



    /// <summary>
    /// This method will retreive info from SQL DataBase.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnRetreive_Click(object sender, RoutedEventArgs e)
    {

        this.Frame.Navigate(typeof(BlankPage1), null);
    }


    /// <summary>
    /// 
    /// </summary>
    public class Customer
    {

        public string Name { get; set; }
        public string Age { get; set; }
        public string Number { get; set; }
    }
}

}

(第2页)代码

     protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var query = conn.Table<Customer>();
        string name = "";
        string age = "";
        string number = "";

        foreach (var message in query)//getting error over here..
        {
            name = name + " " + message.Name;
            age = age + " " + message.Age;
            number = number + " " + message.Number;
        }

        txtData.Text = "Name: " + name + "\nAge: " + age + "\nNumber: " + number;


    }

0 个答案:

没有答案