Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Databound DateTime field question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
justin - 11 Sep 2007 18:47 GMT
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.
ed@lakenine.com - 11 Sep 2007 19:45 GMT
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

> Hello all:
>
[quoted text clipped - 12 lines]
>
> Any help or leads is greatly welcomed! Thank you in advance.
justin - 11 Sep 2007 20:32 GMT
On Sep 11, 2:45 pm, e...@lakenine.com wrote:
> Hi justin,
>
[quoted text clipped - 27 lines]
>
> > 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.
Lit - 12 Sep 2007 01:04 GMT
What about in your update SP check for blank and substitute null

> On Sep 11, 2:45 pm, e...@lakenine.com wrote:
>> Hi justin,
[quoted text clipped - 39 lines]
> before an update on just the TextBox that would work, but I don't see
> anything like that.
justin - 12 Sep 2007 03:21 GMT
> What about in your update SP check for blank and substitute null
>
[quoted text clipped - 41 lines]
> > before an update on just the TextBox that would work, but I don't see
> > anything like that.

Lit -
Great idea, not exactly the angle I was going for but same result. In
my SQL I used a CASE and checked the value, for what it's worth,
here's the SQL

randomDateField = CASE WHEN @randomDateField = '' THEN NULL ELSE
@randomDateField

Works great, thanks everyone.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.