PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Binding DateTimePicker
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Binding DateTimePicker
![]() |
Binding DateTimePicker |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
A DateTimePicker control on my form is bound to a datetime field in a
DataTable. When inserting a new record the default value for DateTimePicker is today's date. However, unless the user changes this date it is not saved to database (NULL is stored instead of today's date). Text fields are stored normally. A TextBox control has similar behavior: if the user leaves a text box blank, NULL is sent to database, but if he enters some text and then deletes it, an empty string is stored. It seems that there is some "Modified" property for every control. In this case I want to store the current date instead of NULL. How can I achive this? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
John,
What have you binded because as this question comes the reason is mostly that there is binded to the text property from the datetime picker. That has to the value property, normally this should go fluently. Cor "John Stivenson" <JohnStivenson@discussions.microsoft.com> schreef in bericht news:A8617AA3-F6BD-4E37-A34C-5C73633CFB04@microsoft.com... >A DateTimePicker control on my form is bound to a datetime field in a > DataTable. > When inserting a new record the default value for DateTimePicker is > today's > date. > However, unless the user changes this date it is not saved to database > (NULL > is stored instead of today's date). Text fields are stored normally. > > A TextBox control has similar behavior: if the user leaves > a text box blank, NULL is sent to database, but if he enters > some text and then deletes it, an empty string is stored. > It seems that there is some "Modified" property for every control. > > In this case I want to store the current date instead of NULL. > How can I achive this? > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Hi,
"John Stivenson" <JohnStivenson@discussions.microsoft.com> wrote in message news:A8617AA3-F6BD-4E37-A34C-5C73633CFB04@microsoft.com... >A DateTimePicker control on my form is bound to a datetime field in a > DataTable. > When inserting a new record the default value for DateTimePicker is > today's > date. > However, unless the user changes this date it is not saved to database > (NULL > is stored instead of today's date). Text fields are stored normally. > > A TextBox control has similar behavior: if the user leaves > a text box blank, NULL is sent to database, but if he enters > some text and then deletes it, an empty string is stored. > It seems that there is some "Modified" property for every control. That right, well it's the Binding that has a (private) modified flag which is triggered by the Control property-Changed event (eg. TextChanged/ValueChanged). The value isn't persisted if the modified flag hasn't been set. > > In this case I want to store the current date instead of NULL. > How can I achive this? Try to set default values on the DataSource. If you're using NET2.0 you can use the DataTable.TableNewRow event. HTH, Greetings > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
"Bart Mermuys" wrote:
> > In this case I want to store the current date instead of NULL. > > How can I achive this? > > Try to set default values on the DataSource. > > If you're using NET2.0 you can use the DataTable.TableNewRow event. It seems as a good solution, but I don't know how to do this. Where should I add TableNewRow event handler? Thanks in advance. |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Hi,
"John Stivenson" <JohnStivenson@discussions.microsoft.com> wrote in message news:9D50C122-47ED-4466-A8A0-4C311FCDBD43@microsoft.com... > "Bart Mermuys" wrote: > >> > In this case I want to store the current date instead of NULL. >> > How can I achive this? >> >> Try to set default values on the DataSource. >> >> If you're using NET2.0 you can use the DataTable.TableNewRow event. > > It seems as a good solution, but I don't know how to do this. > Where should I add TableNewRow event handler? It depends on a couple of things... First, you don't mention that you are using NET2.0, the event is only available in NET2.0, since you consider the option i assume you are. Second, it would also be different depending on how and where you create the DataSet/DataTable which you have bound. And last, the language you are using. // Assuming you are using NET2.0, you've added the // (typed) DataSet/DataTable using the designer and are // using C#, then you would do something like: public partial class SomeForm : Form { public SomeForm() { InitializeComponent(); // add handler after InitializeComponent someDataSet.someDataTable.TableNewRow += new DataTableNewRowEventHandler( OnSomeTable_TableNewRow ); } private void OnSomeTable_TableNewRow( object sender, DataTableNewRowEventArgs e ) { // set default values e.Row["someField1"] = ....; e.Row["someField2"] = ...; ... } } HTH, Greetings > > Thanks in advance. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

