Click here to Skip to main content
15,947,389 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wan to save the date into an access database but didn't work.. how i suppose to do
here is my code :

Dim SelectedDate As Object
SelectedDate = New DateTimePicker()
SelectedDate.Format = DateTimePickerFormat.Time
SelectedDate.ShowUpDown = True
SelectedDate.Location = New Point(10, 10)
SelectedDate.Width = 100
SelectedDate = DateDateTimePicker.Text

What I have tried:

Now I tried to make my datetime value save into an access database
Updated 28-Feb-16 0:52am
Kornfeld Eliyahu Peter 28-Feb-16 6:35am    
Not any string can be converted to date/time...Use the debugger to see what value do you try to convert...

Selected Date is a DateTimePicker, so you can't assign a to it.
So why not just assign the Value from one DTP to the other?
SelectedDate.Value = DateDateTimePicker.Value
Share this answer
MrALiv3 28-Feb-16 9:40am    
ok thank, i will try later
First issue: On the last line you try to overwrite your DateTimePicker-variable SelectedDate with a string (from DateDateTimePicker.Text). That can't work ever. You probably intended to set the .Value-Property of the the DateTimePicker, maybe like this:
SelectedDate.Value = DateTime.Parse(DateDateTimePicker.Text);

Use .TryParse(..) instead if DateDateTimePicker.Text could contain a string that's invalid as a DateTime-string.

(Edit, seeing OG's response): Unless DateDateTimePicker is another DateTimePicker-object, then a) use DateDateTimePicker.Value or maybe DateDateTimePicker.Value.Date or b) reconsider what you're doing there - do you need two DateTimePickers where the value of one is written to the other?)

Next issue (probably): Your error message sounds like you're trying to insert a string into the DateTime-column of your database. You need to provide the DateTime-value instead (which again you get from SelectedDate.Value) for the (Ole)DbParameter.
Don't get the idea of storing a DateTime formatted as a string in the database though. That's the path to far greater problems.

DateTime.Parse Method (String) (System)[^]
DateTime.TryParse Method (System)[^]
Share this answer
MrALiv3 28-Feb-16 9:40am    
Ok thank you, i will try later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900