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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
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.

--
____________________________________
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.
__________________________________
 
Back
Top