I have datetimepicker and next to datetimepicker is textbox.
When I choose date from datetimepicker, selected date goes into textbox.
Works fine.

-- txt1.Text = Format(DateTimePicker1.Value, "dd.MM.yyyy")

Problem is, when selected date from datetimepicker is shown in txt1, that date doesnt want to be saved into database. Database is empty for that value.
When I enter date into txt1 box Manually, then thath date saves into database.

Any ideas?

Datetime picker isn't bounded with datasource, but txt box is.
In database (access) value for "date of birth" field is Date/Time.

Plus: Can I change a date in textbox manually (sometimes) and then automatically date would be changed in date time picker?

Thank you!!

4 Years
Discussion Span
Last Post by bprosic

Can you please share the code where:
a) you assign the value to txt1 (whole thing, including event that fires it)
b) the update the db part

On the plus side: Yes you can, you do the opposite thing (assign the datetimepicker the date from the textbox), but you have to validate the date first (or errors will be generated) and you have to choose an event like lostfocus, because textchanged will try to update the datetimepicker with each keystroke.


Or you can handle it in the KeyUp handler as follows:

Private Sub TextBox1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
    If e.KeyCode = Keys.Enter Then
        If Not IsDate(TextBox1.Text) Then
            MsgBox("not a date")
            e.Handled = True
            'update the database
        End If
    End If
End Sub

I had to do all over again and I started with BindingNavigator.
I used coding for firs time, but something was wrong.

Now it works, just I had to use wizzard.

Thank you for your response.

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.