autogenerate datetime in database

Posted by Saritha.rajeshkumar under C# on 4/25/2011 | Points: 10 | Views : 1814 | Status : [Member] | Replies : 4
hi this saritha, i have 3colums in database username,password,datetime. when i insert username and password, datetime should be generate automatically.




Responses

Posted by: Ndebata on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
Use Getdate()

in your query as field to insert it.

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/25/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Saritha.rajeshkumar

i think date is automatically not insert in database . . u do this by ur query .. by
System.Datetime.Now()

Use it . .

Best Regard's
Prabhakar

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gokul on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
You can use the datetime property in C# by,

DateTime dtm = DateTime.Now.Date;
string currenttime = dtm.TimeOfDay.ToString();

now you can insert the string currenttime into the DB by Query as
string query= insert into Table_Name values('"+txtfirstname+"','"+txtlastname+"','"+dtm+"');


Thanks and Regards
GokulNithy.

Thanks and Regards,
GokulNath Nithy.

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tijut2k on: 4/26/2011 [Member] Starter | Points: 25

Up
0
Down
The Best way is Set Default Value or Binding as GetDate() when you are creating the table .
so you dont need to pass the date when you are inserting rows into particular table..

Default Value or Binding is located in Columns Properties

Best Regard's
Tiju Thankachan

Saritha.rajeshkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response