C# 如何通过在列表框中选择项目来更新数据库-windows phoene 7?

C# 如何通过在列表框中选择项目来更新数据库-windows phoene 7?,c#,windows-phone-7,linq-to-sql,windows-phone-7.1,C#,Windows Phone 7,Linq To Sql,Windows Phone 7.1,我正在开发一个需要更新操作的windows phone 7应用程序。我有下面的表类 [Table] public class StudentTable { [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)] public int StudentID {

我正在开发一个需要更新操作的windows phone 7应用程序。我有下面的表类

[Table]
public class StudentTable
{

    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int StudentID
    {
        get;
        set;
    }

    [Column (CanBeNull = false)]
    public string StudentName
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public string StudentClass
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public DateTime regDate
    {
        get;
        set;
    }
}
我用以下方法获取每个学生的值

 using (StudentDataContext context = new StudentDataContext(strConnectionString))
        {

            StudentTable newStudent = new StudentTable
            {

                StudentName = textBox1.Text.ToString(),
                StudentClass = textBox2.Text.ToString(), 
                regDate = ((DateTime) datePicker.Value).Date.Add(((DateTime)timePicker.Value).TimeOfDay) 

            };

            context.StudentInfo.InsertOnSubmit(newStudent);
            context.SubmitChanges();

        }
并在列表框中显示学生

                 <ListBox HorizontalAlignment="Left"  Name="StudentlistBox1" ItemsSource="{Binding}"  Loaded="StudentlistBox1_Loaded">
                 <ListBox.ItemTemplate>
                     <DataTemplate>
                         <StackPanel>
                               <TextBlock Text="{Binding StudentName}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
                               <TextBlock Text="{Binding StudentClass}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
                               <TextBlock Text="{Binding regDate}" FontSize="{StaticResource PhoneFontSizeSmall}"></TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

我正在尝试编码,以便列表框中的每个选定项都会指向一个页面,在该页面中我可以更新选定的记录。 如果我得到了所选项目的主键,我相信我能做到……我如何在列表框中选择学生并传递该学生id?任何想法……我是windows phone 7的新手……请帮助。

方法1:-通过导航传递详细信息

并在第2页中访问导航到的方法:-

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
像这样:-
QueryString this.NavigationContext.QueryString[“param”]

方法2:-将id存储在IsolatedStorage设置中

并使用appSettings[“paramFromPage1”]通过在第2页中正确解析来检索它

*方法3:-[可能在应用程序LifeTime对象中!!]

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
private IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings["paramFromPage1"]=paramValue;