By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,603 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,603 IT Pros & Developers. It's quick & easy.

Record Date of a Registration form in C#

P: 17
When a user fills all the required information in a registration form then how do I record the date of submitting the form using Sql Server 2005?

My insert query is :

Expand|Select|Wrap|Line Numbers
  1. con.Open();
  2. SqlCommand command = new SqlCommand("insert into data (UserID,Name,Email,Country,Date,Multiselect,Gender,Pincode)values('" + txtuserid.Text + "','" + txtname.Text + "','" + txtemail.Text + "','" + ddlcountry.SelectedItem.Text + "','" + s1 + "','" + lbmultiselect.Text + "','" + rblgender.Text + "','" + txtpincode.Text + "')", con);
  3. command.ExecuteNonQuery();
Nov 18 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,427
Please use code tags when posting code.

In SQL Server, you can use the GETDATE() function to return the current date and time.
Nov 19 '12 #2

Expert Mod 100+
P: 465
To expand on what Rabbit suggested you can set the columns default value to GETDATE() and any time a record is inserted into that table that column will always be set to the current date/time of the insert.


To alter your column to add the default value setting do this

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE [dbo].[YourTableName] ADD  DEFAULT (getdate()) FOR [YourColumnName]
Nov 20 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.