Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

Insert and update date field in asp.net app using access

I want to add a time stamp by inserting the current date when a user inserts or updates a record. This seems to be more difficult then I had expected, probably because I'm new and using Access (maybe issues with date formating).
Would it be best to have a hidden text box that get the current date in the insert item and edit item templates, or, another way. After date is updated, it will be displayed in the item template.

thanks for looking and your suggestions
alan
0
avoorheis
Asked:
avoorheis
  • 2
1 Solution
 
JenniQCommented:
The easiest way (but not the best practice) is to create a text field (nchar or whatever) in the access database called TimeStamp and set the value in ASP.NET to DateTime.Now().ToString()

This will print the time into the db. Then when you want to retrieve it and format, you can pull the string into a DateTime object using DateTime.Parse(string date) and write it out with DateTime.ToShortDateSTring() or whatever formatting you want.
Let me know if this helps.

-- jenni
0
 
avoorheisAuthor Commented:
Hi Jenni,
I bet this will work if I know how to format it in the updatecommand. It works ok if I just replace DateTime.Now().ToString() with 'xxx'.
UpdateCommand="UPDATE tblDisplayInventory SET SF = ?, Dated = DateTime.Now().ToString() WHERE (AccountNo = ?)">
like it is now, I get this error:
Invalid use of '.', '!', or '()'. in query expression 'DateTime.Now().ToString()'.

thanks
0
 
avoorheisAuthor Commented:
this worked
Dated = Now()
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now