0

I have one query in vb.net.i am trying to insert date to SQL Database but when i click inset button then show me a error message above.Please if you can help me so i need yours advice.Thanks my code is below. 'In SQL database @DtoDOB Data type is Date.

cmd.Parameters.Add("@DtpDOB", SqlDbType.Date.ToString("dd-mm-yyyy")).Value = DtpDOB.Value
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • `SqlDbType.Date` is an Enum, not a Date. Why are you calling `.ToString()` on it anyway? You seem to be trying to set the date format. That's not required and even if it was, you're doing it wrong. – 41686d6564 stands w. Palestine Apr 07 '20 at 18:31
  • Please now tell me what is right code for this? – Official BaRyaR Apr 07 '20 at 20:33
  • You just need to remove the `.ToString(..)` part as I mentioned above. Use `cmd.Parameters.Add("@DtpDOB", SqlDbType.Date).Value = DtpDOB.Value`. – 41686d6564 stands w. Palestine Apr 07 '20 at 20:52
  • i have try this parameter But now one more error show 'Failed to convert parameter value from a String to a Int32.' – Official BaRyaR Apr 08 '20 at 13:09
  • This continually marginally evolving problem now has an answer here: ['Failed to convert parameter value from a String to a Int32/](https://stackoverflow.com/questions/61108665/failed-to-convert-parameter-value-from-a-string-to-a-int32) - this question should be closed or deleted – Caius Jard Apr 10 '20 at 05:57

0 Answers0