inserting date created with new record

D

dean.h.brown

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
 
J

Jeff Dillon

How about GetDate()

Transact-SQL

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

Jeff
 
D

dean.h.brown

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top