Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > inserting date created with new record

Reply
Thread Tools

inserting date created with new record

 
 
dean.h.brown@gmail.com
Guest
Posts: n/a
 
      04-24-2008
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
 
Reply With Quote
 
 
 
 
Jeff Dillon
Guest
Posts: n/a
 
      04-24-2008
How about GetDate()

Transact-SQL

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

Jeff

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
dean.h.brown@gmail.com
Guest
Posts: n/a
 
      04-30-2008
On Apr 24, 7:57 pm, "Jeff Dillon" <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview won't update after inserting new record to MS Accessdatabase using OLEDB ggoldab@gmail.com ASP .Net Web Controls 1 09-22-2008 11:23 PM
Inserting a new record into a collection in a action form from a jsp simon_s_li@hotmail.com Java 1 10-13-2007 10:48 PM
Default value when inserting new record with the DetailsView Nick ASP .Net 0 02-24-2006 09:01 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Inserting A New Record Curt Emich ASP .Net 2 05-06-2004 02:27 AM



Advertisments