views:

125

answers:

1

I'm using Subsonic 2, SQL Server 2005.

Here is how I update intro_accepted column of a Member table record.

member.Showintro = true;
member.IntroAcceptby = AdminUser.Username;
member.IntroAccepted = DateTime.Now; // but I wan't getdate() from SQL Server
member.Save();

What is the easiest way to select getdate() from database and put it into intro_accepted column?

+1  A: 
  1. Set the column IntroAccepted in your DB to allow nulls and give it a default value of GetDate.

  2. Regenerate your model and SubSonic will make the IntroAccepted property nullable

  3. Don't specify the value of IntroAccepted (leave it as null) in your code and when you call Save SQL will spot that there's no value for IntroAccepted and use GetDate to populate it.

-

member.Showintro = true;
member.IntroAcceptby = AdminUser.Username;
member.IntroAccepted = null; // You don't actually need to do this as a nullable date will be null by default
member.Save();
Adam
Can you give code snippet?
Anwar Chandra
I've added a code snippet for part 3, is that what you wanted?
Adam