Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inserting date created with new record

1 view
Skip to first unread message

dean.h...@gmail.com

unread,
Apr 24, 2008, 12:24:03 PM4/24/08
to
I'm trying to set the date created when I add a new record: (using a
FormView)

This works:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString
%>"
InsertCommand="INSERT INTO [AdultEvent] ([DateCreated],
[DateLastModified], [EventName])
VALUES ('04/23/2008', '04/23/2008', @EventName)"

but I want the dates to be the current date and time.

I've tried variations on this:
VALUES ('<%$ DateTime.Now.ToString('MM/dd/yyyy') %>', '04/23/2008',
@EventName)"

But I get:
System.Data.SqlClient.SqlException: Incorrect syntax near 'MM'.

Or:
VALUES ('<%$ DateTime.Now %>', '04/23/2008', @EventName)"

System.Data.SqlClient.SqlException: Conversion failed when converting
datetime from character string

Jeff Dillon

unread,
Apr 24, 2008, 7:57:38 PM4/24/08
to
How about GetDate()

Transact-SQL

But I would recommend against direct sql inserts like that. Look up "SQL
Injection"

Jeff

<dean.h...@gmail.com> wrote in message
news:cb8d3724-bfe3-4934...@27g2000hsf.googlegroups.com...

dean.h...@gmail.com

unread,
Apr 30, 2008, 8:49:37 AM4/30/08
to
On Apr 24, 7:57 pm, "Jeff Dillon" <jeffdil...@hotmailremove.com>
wrote:

> How about GetDate()
>
> Transact-SQL
>
> But I would recommend against direct sql inserts like that. Look up "SQL
> Injection"
>

I don't think SQL injections apply here - there's no chance to change
this value by external means

0 new messages