如何将从datepicker中检索到的日期保存到windows phone 7中的数据库中?

时间:2013-01-01 11:07:59

标签: c# silverlight windows-phone-7 datepicker windows-phone-7.1

如何将从datepicker中检索到的日期保存到数据库中?。我添加了工具箱window.phone.control.toolkit并在我的xaml页面中添加了这一行。

 <toolkit:DatePicker ValueChanged="DatePicker_ValueChanged" Margin="296,0,0,552" />

这是我的事件处理程序,我得到选择的日期,但是如何将日期值传递到我的数据库中,以将其保存在我的日期coloumn中?

private void DatePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
    {
        var date = e.NewDateTime;
    } 

我使用此代码将项目添加到我的数据库,其中我有2列Studentname(类型字符串)和日期(DateTime)

using (StudentDataContext Expdb = new StudentDataContext(strConnectionString))
        {
            Student StudentInfo = new Student
            {

               StudentName = textBox.Text.ToString(),

               StudentDate = ????


            };

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

为了保存用户选择存储在表格中的日期,我写了什么代码?我是windows手机编程和silverlight的新手,请帮忙吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码来获取日期时间

Student StudentInfo = new Student
{
     StudentName = textBox.Text.ToString(),
     StudentDate = (DateTime)datePicker1.Value;
};
db.StudentInfo.InsertOnSubmit(newStudent);
db.SubmitChanges();

此处datePicker1是DatePicker控件的名称