Reputation: 101
I have a doubt in Asp.Net that is Whenever click the button i want to store the current time into database using Onclick, can anybody suggest me please.
Thank you
Upvotes: 1
Views: 1571
Reputation: 3281
Use DateTime.Now
in asp.net .....
SqlConnection conn = new SqlConnection("your connection string");
SqlCommand cmd = new SqlCommand("INSERT INTO table_name (username, logindate) VALUES (@USERNAME, @DATE)", conn);
cmd.Parameters.AddWithValue("@USERNAME", tbUserName.Text);
cmd.Parameters.AddWithValue("@DATE", DateTime.Now);
int i = cmd.ExecuteNonQuery();
Upvotes: 0
Reputation: 4101
If you are using SQL Server you can store the current time by using GETDATE() function in SQL.
Such as :
INSERT INTO MyTable(Id,ClickTime) VALUES (5, GETDATE())
Upvotes: 1