初心者の質問かもしれませんが、私はWPFアプリケーション、C#のdatepickerフィールドから日付(yyyy-mm-dd)を取得したいと思います。 DateTimeメソッドで日付を保存する必要があることはわかっています。これは、これをデータベースに挿入するためです。プロパティ.DatePickerでは.Valueを使用できません。
どこでも私は彼らが.Valueプロパティを使うと言いますが、DatePickerの後に.Valueプロパティを入力するとプロパティを再調整しません。
誰かがこれを修正する方法を知っているのですか、またはdatepickerから日付を取得する別の方法がありますか?
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));
}
}
コードを表示します。 – Gusman
https://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.selecteddate(v=vs.110).aspx –
WPFでは、それは 'Value'ではなく' SelectedDate'と呼ばれています。 Windowsフォームコントロールは、「DateTimePicker」と呼ばれ、「Value」プロパティを持っています。 –