【发布时间】:2017-10-30 04:14:54
【问题描述】:
这可能是一个初学者的问题,但我想从 WPF 应用程序 C# 中的日期选择器字段中获取日期 (yyyy-mm-dd)。我知道我必须使用 DateTime 方法保存日期,因为我要将它插入到数据库中。
我在互联网上看到的每个地方都说使用 .Value 属性,但如果我在 DatePicker 之后键入 .Value 属性,它不会重新调整该属性。
有人知道如何解决此问题或有其他方法从日期选择器中获取日期吗?
private void btnPlanGP_Click(object sender, RoutedEventArgs e)
{
try
{
string grandPrixNaam = naamGPTextBox.Text;
DateTime datumGP = new DateTime();
datumGP = datumDatePicker.Value;
int aantalRondes = Convert.ToInt32(aantalRondesTextBox.Text);
string naamBaan = naamBaanComboBox.SelectedItem.ToString();
int coureurID = Convert.ToInt32(coureurIDComboBox.SelectedItem);
int gastID = Convert.ToInt32(gastIDComboBox.SelectedItem);
try
{
formule1DataSetGrandPrixTableAdapter.Insert(grandPrixNaam, datumGP, naamBaan, aantalRondes, coureurID, gastID);
formule1DataSetGrandPrixTableAdapter.Fill(formule1DataSet.GrandPrix);
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(Convert.ToString(ex));
}
}
【问题讨论】:
-
显示你的代码。
-
在 WPF 中,它被称为
SelectedDate,而不是Value。 Windows 窗体控件称为DateTimePicker,并具有Value属性。
标签: c# wpf date datepicker