Record Date of a Registration form in Asp.net C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • developerquery
    New Member
    • Jun 2012
    • 17

    Record Date of a Registration form in Asp.net C#

    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 :

    Code:
    con.Open();
    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);
    command.ExecuteNonQuery();
    Last edited by Rabbit; Nov 19 '12, 01:21 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    In SQL Server, you can use the GETDATE() function to return the current date and time.

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      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.

      EDIT:

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

      Code:
      ALTER TABLE [dbo].[YourTableName] ADD  DEFAULT (getdate()) FOR [YourColumnName]
      Last edited by PsychoCoder; Nov 20 '12, 07:33 PM.

      Comment

      Working...