How use NOW() function in InsertCommand

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

In my HTML view of my ASPX page how do I use the NOW() function for the
InsertCommand? This doesn't seem to work...

Code snippet:
<asp:SqlDataSource ID="sdsPress" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [pressReleases] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [pressReleases] ([UserId],
[PressTitle], [PressDescription], [CompanyName], [CompanyLocation],
[DateAdded], [Flagged]) VALUES (@UserId, @PressTitle, @PressDescription,
@CompanyName, @CompanyLocation, <% =Date.now() %>, 0)"
 
Why not just use what the database has built into it. In this case just pass
the fucntion as one of your values. For example, in SQL Server it would be
GetDate() and used like so:

.... @CompanyName, @CompanyLocation, GetDate(), 0)"

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
 
That's a great idea Mark!

Mark Fitzpatrick said:
Why not just use what the database has built into it. In this case just
pass the fucntion as one of your values. For example, in SQL Server it
would be GetDate() and used like so:

... @CompanyName, @CompanyLocation, GetDate(), 0)"

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

Cirene said:
In my HTML view of my ASPX page how do I use the NOW() function for the
InsertCommand? This doesn't seem to work...

Code snippet:
<asp:SqlDataSource ID="sdsPress" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [pressReleases] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [pressReleases] ([UserId],
[PressTitle], [PressDescription], [CompanyName], [CompanyLocation],
[DateAdded], [Flagged]) VALUES (@UserId, @PressTitle, @PressDescription,
@CompanyName, @CompanyLocation, <% =Date.now() %>, 0)"
 
Back
Top