0

I have made a registration form using C# and the record will be saved in sql. I want to also add a record of the registration date automatically. How to do this?

Edited by AngelicOne: n/a

5
Contributors
15
Replies
16
Views
7 Years
Discussion Span
Last Post by crishjeny
Featured Replies
  • I'm confused, are you wanting to record the date of the registration within the information you're recording about the registration? Or in a separate record/table? If you simply want the current date/time within the same record it's as simple as adding a date/time column in your table and populating it … Read More

  • You can open your table in Desing mode,add the column of registration date with datatype of datetime then go to column properties and in "default value or binding" properties add "getDate()" without qout as value. Now save the table, From now on you do not need to do anything, whenever … Read More

  • why to increase code.. if you are using the current date and time let the sql server help you.. mono_jit23 has given the best deal.. :) your way okey but the thing is you can control the TV via Remote..why do you need to go to TV and change the … Read More

  • Ok, Umm... If you have SQL Server Management Tools available for you for the DB you're working on do this:[LIST=1] [*]choose the Date_Registered column within your table [*]Column Properties > General > Default Value or Binding [*]Enter "getDate()" (without quotes) [/LIST]It may give you some grief over the fact that … Read More

1

I'm confused, are you wanting to record the date of the registration within the information you're recording about the registration? Or in a separate record/table?

If you simply want the current date/time within the same record it's as simple as adding a date/time column in your table and populating it either from the code-behind side with DateTime.Now or on the SQL side with (I think) dateTime.Now() (been a while since I used the commands directly within SQL).

Votes + Comments
thanks
2

You can open your table in Desing mode,add the column of registration date with datatype of datetime then go to column properties and in "default value or binding" properties add "getDate()" without qout as value. Now save the table, From now on you do not need to do anything, whenever a new row is added this column value will be generated automatically... hope this helps...:)

Votes + Comments
That's what I was getting at :)
0
cmd.Parameters.Add("@Date_Registered", SqlDbType.DateTime).Value = DateTime.Now;
1

why to increase code..

if you are using the current date and time

let the sql server help you..

mono_jit23 has given the best deal.. :)

your way okey but the thing is you can control

the TV via Remote..why do you need to go to TV and change the Channel Manually.. :)

Edited by dnanetwork: n/a

Votes + Comments
good example
0

I tried this but Insert Error: Column name or number of supplied values does not match table definition.

SQL

Date_Registered DATETIME DEFAULT GETDATE()
1

Ok, Umm... If you have SQL Server Management Tools available for you for the DB you're working on do this:

  1. choose the Date_Registered column within your table
  2. Column Properties > General > Default Value or Binding
  3. Enter "getDate()" (without quotes)

It may give you some grief over the fact that prior fields may or may not be already filled in but it will achieve what was suggested by mono.

Alternately, as this is now several days old and it's still not doing what you wanted it to do why not just give up on that if you can't figure it out and instead have the date generated on the application side and inserted at the time of the record being sent like I originally said :)

Either works, mono's method works behind the scenes and without fuss but you seem to be having difficulty implementing it.

See, this is what happens when I buy a new game and take a few days off DaniWeb :twisted:

Votes + Comments
nice comeback.. xP
0

I even tried inserting a record in the table itself..

Here is an example:

CREATE Table tbl (Name nvarchar(50), Date_Registered DATETIME DEFAULT GETDATE())
INSERT INTO tbl VALUES ('mark')

I believe I don't need to put a second value because date_registered will automatically add a datetime.

0

Well if you set up the table to have the columnn auto-populate then you are correct, you would not need to add a value when submiting a row from your program.

It's only if you do NOT have the column auto-populating dateTime that you would still need to insert a value at the time that the new row is entered.

0

Even though I entered default getdate(), the value of default binding under general is empty. I tried putting getdate() but I can't enter a value inside it.

0

I choose modify instead properties and still with getdate(), it doesn't work.

Insert Error: Column name or number of supplied values does not match table definition.

Edited by AngelicOne: n/a

0

It's working now if I include the columns names i.e

INSERT INTO tbl (name) values ('mark')
0

Hi

Its nothing but it takes just current date and time for registration.you will refer the following code to solve the issue of registration date.

syntax:

CurrentDate.Text = DateTime.Now.ToString()

objCustomer.currentDate = txtDate.Text

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.