Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

inserting date created with new record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dean.h.brown@gmail.com - 24 Apr 2008 17:24 GMT
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 - 25 Apr 2008 00:57 GMT
How about GetDate()

Transact-SQL

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

Jeff

> I'm trying to set the date created when I add a new record: (using a
> FormView)
[quoted text clipped - 21 lines]
> System.Data.SqlClient.SqlException: Conversion failed when converting
> datetime from character string
dean.h.brown@gmail.com - 30 Apr 2008 13:49 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.