datetimepicker dataset

G

Guest

When adding a new record from my form, I pre-set my DateTimePicker's value to
System.DateTime.Today
Since the "Today" value is used most of the time, the user doesn't need to
select a date from the DateTimePicker, since the default is shown. My problem
is, if the user does not choose a value from the DateTimePicker (because
using the default is good enough), then during database update, the date
value is not saved to the database; while if user choose another value other
then the default, the value can be saved to the database successfully. Is
there a way to ensure the default value can be saved to the database?
 
G

Guest

I think you misunderstand me...

PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS

try this with vb.net 2003

create with the dataform wizard a form that bind to a simple sql table with
productID and dateofproduct (datetime and not nullable).
If you show the form the load event put as dateofproduct default the today's
date but if you try to update the dataset without touch the datetimepicker
control the dataset reject to update cause the datetimepicker value is null.
While if I touch the datetimepicker control and i choose a date the update
works.

My problem
is, if the user does not choose a value from the DateTimePicker (because
using the default is good enough) the update doesn't works.

I haved try to set datetimepicker.value = now() during the load event but it
doesn't work.
 
E

Earl

I think I understand you. You need to pass a non-null date value to the
dataset when the datetimepicker has not been selected. This is indeed the
way I would do it (and have done it).

But without any code, there is much that all of us would be speculating
upon. How are the datetimepicker values being passed to the dataset? What
causes the the update to be applied to the backend database?

Fundamentally, the answer is the same however you are coding it -- you
either need to pass a non-null Date value (if Today.Date is acceptable), or
you need to protect for null being passed (another way of doing it).

To get a better answer, you will have to show the code snippet.
 
K

Ken Tucker [MVP]

Hi,

http://www.windowsforms.net/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=948

Ken
----------------
When adding a new record from my form, I pre-set my DateTimePicker's value
to
System.DateTime.Today
Since the "Today" value is used most of the time, the user doesn't need to
select a date from the DateTimePicker, since the default is shown. My
problem
is, if the user does not choose a value from the DateTimePicker (because
using the default is good enough), then during database update, the date
value is not saved to the database; while if user choose another value other
then the default, the value can be saved to the database successfully. Is
there a way to ensure the default value can be saved to the database?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top