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

how to insert date and time into sqldatabase

shivananda
P: 9
hope every one doing well
i am new to vb.net when iam try to insert datetime into sqldatabase it is not inserting here is my code.
here unable to convert the datetime while inserting into database logs table

Expand|Select|Wrap|Line Numbers
  1.  con.open()
  2.  Dim cmd As New SqlCommand("INSERT INTO logs ([username],[date_time])VALUES(@username,@datetimepicker1)", con)
  3.                     With cmd.Parameters
  4.                         .AddWithValue("@username", username.Text)
  5.                         .AddWithValue("@date_time",datetimepicker1.text)
  6.                     End With
  7.                     cmd.ExecuteNonQuery()
  8.                     cmd.Dispose()
  9.                     con.Close()
May 17 '13 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,382
Your parameters are named differently.
May 17 '13 #2

100+
P: 158
Hey shivananda, line number 5 in your code replace '@date_time' by '@datetimepicker1'.
May 17 '13 #3

shivananda
P: 9
hi vijay
its working
thank you for the suggestion
May 18 '13 #4

Post your reply

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