468,306 Members | 1,246 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,306 developers. It's quick & easy.

Databound DateTime field question

Hello all:

I have a FormView that has it's DataSourceID set to a SqlDataSource
that uses stored procedures for it's select, update, insert, and
delete. I want the FormView to have an "autosave" feature, so based on
certain intervals or user interactions I call the

FormView.UpdateItem(false); function in my C# code behind.

My problem is that a TextBox that I have in my FormView is bound to a
DateTime column in the database, and if no value is in the TextBox
then a date of Jan. 1, 1900 is saved to the database. The column
accepts null values. How can I get my TextBoxes that are bound to
DateTime columns save null when no value has been entered?

Any help or leads is greatly welcomed! Thank you in advance.

Sep 11 '07 #1
2 1984
ed
Hi justin,

Assuming that your underlying SQL datatype is smalldatetime (1/1/1900
is the smalldatetime type's minimum value) it looks like the value
from the textbox is being treated as blank, not null. You're going to
have to jump in somewhere and swap that blank for a null when you
update.

Does that give you enough to work with? If not, I'd recommend posting
your function and/or your SP's -- perhaps even the non-default
properties to the bound textbox.

Hope this helps,
Ed

On Sep 11, 1:47 pm, justin <justin.cre...@gmail.comwrote:
Hello all:

I have a FormView that has it's DataSourceID set to a SqlDataSource
that uses stored procedures for it's select, update, insert, and
delete. I want the FormView to have an "autosave" feature, so based on
certain intervals or user interactions I call the

FormView.UpdateItem(false); function in my C# code behind.

My problem is that a TextBox that I have in my FormView is bound to a
DateTime column in the database, and if no value is in the TextBox
then a date of Jan. 1, 1900 is saved to the database. The column
accepts null values. How can I get my TextBoxes that are bound to
DateTime columns save null when no value has been entered?

Any help or leads is greatly welcomed! Thank you in advance.

Sep 11 '07 #2
On Sep 11, 2:45 pm, e...@lakenine.com wrote:
Hi justin,

Assuming that your underlying SQL datatype is smalldatetime (1/1/1900
is the smalldatetime type's minimum value) it looks like the value
from the textbox is being treated as blank, not null. You're going to
have to jump in somewhere and swap that blank for a null when you
update.

Does that give you enough to work with? If not, I'd recommend posting
your function and/or your SP's -- perhaps even the non-default
properties to the bound textbox.

Hope this helps,
Ed

On Sep 11, 1:47 pm, justin <justin.cre...@gmail.comwrote:
Hello all:
I have a FormView that has it's DataSourceID set to a SqlDataSource
that uses stored procedures for it's select, update, insert, and
delete. I want the FormView to have an "autosave" feature, so based on
certain intervals or user interactions I call the
FormView.UpdateItem(false); function in my C# code behind.
My problem is that a TextBox that I have in my FormView is bound to a
DateTime column in the database, and if no value is in the TextBox
then a date of Jan. 1, 1900 is saved to the database. The column
accepts null values. How can I get my TextBoxes that are bound to
DateTime columns save null when no value has been entered?
Any help or leads is greatly welcomed! Thank you in advance.
That makes sense, but I guess I'm not sure how to "jump in somewhere".
I don't see any events for the TextBox that would happen before
updating the database.

I can think of a few ways to replace the DateTime value if I wasn't
using the SqlDataSource and the update StoredProcedure, but what I'm
really looking for is something that will work with the DataSource. If
there was a default value for the TextBox or an event that fired
before an update on just the TextBox that would work, but I don't see
anything like that.

Sep 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Carl | last post: by
44 posts views Thread by Frank Rizzo | last post: by
8 posts views Thread by bienwell | last post: by
reply views Thread by Benny Dein | last post: by
5 posts views Thread by iulian.ilea | last post: by
6 posts views Thread by =?Utf-8?B?QmVuLg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.