从SQLITE DB将值设置为Datepicker和Listpicker

时间:2014-07-21 08:54:01

标签: c# sqlite windows-phone-8

我正在编写代码,用于将数据从SQLITE数据库提取到Windows Phone应用程序页面上添加的控件。 在我的页面中有一个TextBox,DatePicker& Listpicker,来自SQLITE查询我正在获取数据,但它只显示在TextBox字段中,未显示在其他控件中,如DatePicker和ListPicker。

Xaml代码:

<toolkit:DatePicker Name="dpkDate" Margin="0,144,0,332" />
<toolkit:ListPicker x:Name="priority" Margin="10,233,10,188" ExpansionMode="ExpansionAllowed" Background="#FFF7EBEB" SelectedIndex="2">
    <ListBoxItem x:Name="high" Content="High" Foreground="Black"/>
    <ListBoxItem x:Name="medium" Content="Medium" Foreground="Black"/>
    <ListBoxItem x:Name="low" Content="Low" Foreground="Black"/>
</toolkit:ListPicker>
<ListBox HorizontalAlignment="Left" Height="287" VerticalAlignment="Top" Width="456" Name="TaskListBox" Margin="10,302,-10,0" Visibility="Collapsed"/>
<TextBox HorizontalAlignment="Left" Height="134" Margin="0,5,0,0" TextWrapping="Wrap" Text="Wrpite Note" VerticalAlignment="Top" Width="456" Name="TextField"/>

.cs代码

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    dbConn = new SQLiteConnection(DB_PATH);
    // Create the table Task, if it doesn't exist.
    dbConn.CreateTable<Task>();
    // Retrieve the task list from the database.

    try
    {
        string id = NavigationContext.QueryString["selectedItem"].ToString();
        //string note = NavigationContext.QueryString["selectedItem.Text"].ToString();
        //MessageBox.Show(id); //this retrive the index of selected item and display in message

        var note= dbConn.Query<Task>("select * from task where Id='" + id + "'").FirstOrDefault();
        if (note == null)
            MessageBox.Show("Note Not Present in DataBase");
        else
        {
            TextField.Text = note.Text;
            dpkDate.Value = DateTime.Parse(note.Text);
            ((ListBoxItem)priority.SelectedItem).Content = note.Text;
        //     Date = dpkDate.Value.Value.ToString(),
        //Text = TextField.Text,
        //Priority=((ListBoxItem)priority.SelectedItem).Content.ToString(), //here have to make change to get 

        }

    }
    catch { }
    // Create the database connection.

}

我哪里错了?请帮忙。 注意:&#34; http://prntscr.com/44sbux&#34;你可以看到这里的截图,我不能在这里张贴截图。

根据要求:类Task的结构 //表示Task表的Task类。类中的每个属性都成为数据库中的一个属性。

public sealed class Task
{
    /// <summary>
    /// You can create an integer primary key and let the SQLite control it.
    /// </summary>
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public String Date { get; set; }

    public string Text { get; set; }

    public String Priority { get; set; }

    public override string ToString()
    {
        return "------------------------------------\n "+ Id +"\n" + Date + "\n" + Text + " \n " + Priority + " \n------------------------------------ ";
    }
}

0 个答案:

没有答案