Parameter issue with DateTime

I am getting an error when trying to insert the datetime into an sql table. There error message I am getting is
Failed to convert parameter value from a String to a DateTime.
any help would be appreciated.
db.AddInParameter(dbCommand, "@datecreated", DbType.DateTime, ("MM/dd/yyyy"));

Open in new window

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Did you try changing "(MM/dd/yyy)" to your variable name like:
DateTime somdDate = DateTime.Now;  // example datetime variable
db.AddInParameter(dbCommand, "@datecreated", DbType.DateTime, someDate);

Open in new window

käµfm³d 👽Commented:
Off the bat, I would say that ("MM/dd/yyyy") is causing the issue. But to be safe--what object type is db?
What Db engine are you using (Sql Server, Oracle, Mysql, Access, ..)

If Mysql the date should be in the following format: "yyyy-mm-dd"
What is the datetime value you are passing to the DB?
mockwebAuthor Commented:
Database db = DatabaseFactory.CreateDatabase("SQLConnectionString");
                string sqlCommand = "stp_librarysuggestionInsertNew";
                DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.