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 / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

How to initialice a default value for a column in a typed DataSet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaime Stuardo - 03 Jan 2006 21:16 GMT
Hi all...

I have a typed dataset that corresponds to a SQL Server database model.

I have in a table a datetime column that cannot be null, but it has a
default value of getdate().

How can I set the default value for the corresponding DataSet table? I tried
using getdate() or DateTime.Today for the column DefaultValue property but
without success..

Any help will be greatly appreciated

Thanks
Jaime
Cowboy (Gregory A. Beamer) - MVP - 05 Jan 2006 17:24 GMT
GetDate() is SQL Server, so it is a non option.

The default in a strongly typed dataset is a literal, not a programatic
value. You cannot use DateTime.Now or DateTime.Today for this value, as it
tries to insert the literal string "DateTime.Now" which is not a valid date.
Boom!

You can, conceivably set a literal default, like 1/1/1900, but you have to
watch this, as this value could end up munging up the validity of your data.

ANother option is allow nulls on the DataSet and have the update method with
the GetDate() default (or, better yet, the field in the database table). The
downside of this method is a data disconnect between initial creation and
save (the client app sees a "nothing" while the database has a datetime).

Another option is seeding the default when a new row is created. This can be
custom, or you can use one of the built in events to capture the creation.
This matches your initial state to the database when the update is called.

This is fairly unique to types like DateTime where the default has to be
dynamic.
Signature

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

> Hi all...
>
[quoted text clipped - 11 lines]
> Thanks
> Jaime
William (Bill) Vaughn - 05 Jan 2006 18:07 GMT
Ah, my approach has always been to create a DEFAULT in SQL Server and bind
it to the column. The DEFAULT can be an expression like GETDATE(). Perhaps
I'm missing something, but this should work. When executing the UPDATE or
INSERT don't include the column so the server-side default kicks in.

Signature

____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

> GetDate() is SQL Server, so it is a non option.
>
[quoted text clipped - 40 lines]
>> Thanks
>> Jaime

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.