Hello,
I'm trying to data bind a DateTimePicker to a property of a custom object, like:
Code:
this.dtpDateTimeField.DataBindings.Add("Value", this._typefield, "DateTimeField");
TypeField is the name of the object. "DateTimeField" is the field I'm binding to.
Then I input some data and do an insert into a Jet database.
I have the default value of the date time field in the object set like:
Code:
private System.DateTime _dateTimeField = DateTime.Now;
so the DateTimePicker has a defult value of todays date when the form loads.
Here's the initializing code from the designer:
[code]
this.dtpDateTimeField.Value = new System.DateTime(2008, 10, 26, 0, 0, 0, 0);
If I actually SELECT a date in the DateTimePicker after the form loads, and then
click a Save button that does the insert, all goes well.
However, if I don't actually click on the DateTimePicker and SELECT a date (but just try
and insert the default value), all goes bad. I get:
OleDbException was unhandled, data type mismatch in criteria expression.
The value isn't null anywhere I can see. There seems to be a genuine DateTime value getting
passed around either way. I've even tried adding my own binding and played with formatting and parsing
events:
Code:
Binding b = new Binding("Value", this._typefield, "DateTimeField", true);
this.dtpDateTimeField.DataBindings.Add(b);
b.Format += new ConvertEventHandler(dtpDateTimeField_Format);
b.Parse += new ConvertEventHandler(dtpDateTimeField_Parse);
but no luck.
Any thoughts.
Bob